Commit 46bf3a09 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactored profile to resource. Added missing flash notice on successfull...

Refactored profile to resource. Added missing flash notice on successfull updated. Update username via ajax
parent 2be5e6d4
......@@ -8,3 +8,13 @@ $ ->
# Go up the hierarchy and show the corresponding submission feedback element
$(@).closest('fieldset').find('.update-feedback').show('highlight', {color: '#DFF0D8'}, 500)
$('.update-username form').on 'ajax:before', ->
$('.loading-gif').show()
$(this).find('.update-success').hide()
$(this).find('.update-failed').hide()
$('.update-username form').on 'ajax:complete', ->
$(this).find('.save-btn').removeAttr('disabled')
$(this).find('.save-btn').removeClass('disabled')
$(this).find('.loading-gif').hide()
class ProfileController < ApplicationController
class ProfilesController < ApplicationController
before_filter :user
layout 'profile'
def show
end
......@@ -7,8 +8,15 @@ class ProfileController < ApplicationController
def design
end
def account
end
def update
@user.update_attributes(params[:user])
if @user.update_attributes(params[:user])
flash[:notice] = "Profile was successfully updated"
else
flash[:alert] = "Failed to update profile"
end
respond_to do |format|
format.html { redirect_to :back }
......@@ -19,7 +27,7 @@ class ProfileController < ApplicationController
def token
end
def password_update
def update_password
params[:user].reject!{ |k, v| k != "password" && k != "password_confirmation"}
if @user.update_attributes(params[:user])
......@@ -31,14 +39,25 @@ class ProfileController < ApplicationController
end
def reset_private_token
current_user.reset_authentication_token!
redirect_to profile_account_path
if current_user.reset_authentication_token!
flash[:notice] = "Token was successfully updated"
end
redirect_to account_profile_path
end
def history
@events = current_user.recent_events.page(params[:page]).per(20)
end
def update_username
@user.update_attributes(username: params[:user][:username])
respond_to do |format|
format.js
end
end
private
def user
......
......@@ -6,17 +6,17 @@
= render "layouts/head_panel", title: "Profile"
.container
%ul.main_menu
= nav_link(path: 'profile#show', html_options: {class: 'home'}) do
= nav_link(path: 'profiles#show', html_options: {class: 'home'}) do
= link_to "Profile", profile_path
= nav_link(path: 'profile#account') do
= link_to "Account", profile_account_path
= nav_link(path: 'profiles#account') do
= link_to "Account", account_profile_path
= nav_link(controller: :keys) do
= link_to keys_path do
SSH Keys
%span.count= current_user.keys.count
= nav_link(path: 'profile#design') do
= link_to "Design", profile_design_path
= nav_link(path: 'profile#history') do
= link_to "History", profile_history_path
= nav_link(path: 'profiles#design') do
= link_to "Design", design_profile_path
= nav_link(path: 'profiles#history') do
= link_to "History", history_profile_path
.content= yield
%h1 Profile
......@@ -15,7 +15,7 @@
%span.cred.right
keep it secret!
.padded
= form_for @user, url: profile_reset_private_token_path, method: :put do |f|
= form_for @user, url: reset_private_token_profile_path, method: :put do |f|
.data
%p.slead
Private token used to access application resources without authentication.
......@@ -31,7 +31,7 @@
%fieldset
%legend Password
= form_for @user, url: profile_password_path, method: :put do |f|
= form_for @user, url: update_password_profile_path, method: :put do |f|
.padded
%p.slead After successful password update you will be redirected to login page where you should login with new password
-if @user.errors.any?
......@@ -53,16 +53,24 @@
%fieldset
%fieldset.update-username
%legend
Username
%small.right
%small.cred.right
Changing your username can have unintended side effects!
= form_for @user, url: profile_update_path, method: :put do |f|
= form_for @user, url: update_username_profile_path, method: :put, remote: true do |f|
.padded
= f.label :username
.input
= f.text_field :username, required: true
&nbsp;
%span.loading-gif.hide= image_tag "ajax_loader.gif"
%span.update-success.cgreen.hide
%i.icon-ok
Saved
%span.update-failed.cred.hide
%i.icon-ok
Failed
.input
= f.submit 'Save username', class: "btn save-btn"
......
= form_for @user, url: profile_update_path, remote: true, method: :put do |f|
= form_for @user, url: profile_path, remote: true, method: :put do |f|
%fieldset.application-theme
%legend
Application theme
......
......@@ -8,7 +8,7 @@
%hr
= form_for @user, url: profile_update_path, method: :put, html: { class: "edit_user form-horizontal" } do |f|
= form_for @user, url: profile_path, method: :put, html: { class: "edit_user form-horizontal" } do |f|
-if @user.errors.any?
%div.alert-message.block-message.error
%ul
......@@ -39,9 +39,9 @@
- if Gitlab.config.omniauth_enabled? && @user.provider?
%li
%p.hint
%p
You can login through #{@user.provider.titleize}!
= link_to "click here to change", profile_account_path
= link_to "click here to change", account_profile_path
.row
.span7
......
- if @user.valid?
:plain
$('.update-username .update-success').show();
- else
:plain
$('.update-username .update-failed').show();
......@@ -69,14 +69,18 @@ Gitlab::Application.routes.draw do
#
# Profile Area
#
get "profile/account" => "profile#account"
get "profile/history" => "profile#history"
put "profile/password" => "profile#password_update"
get "profile/token" => "profile#token"
put "profile/reset_private_token" => "profile#reset_private_token"
get "profile" => "profile#show"
get "profile/design" => "profile#design"
put "profile/update" => "profile#update"
resource :profile, only: [:show, :update] do
member do
get :account
get :history
get :token
get :design
put :update_password
put :reset_private_token
put :update_username
end
end
resources :keys
......
......@@ -54,7 +54,7 @@ module SharedPaths
end
Given 'I visit profile account page' do
visit profile_account_path
visit account_profile_path
end
Given 'I visit profile SSH keys page' do
......@@ -62,15 +62,11 @@ module SharedPaths
end
Given 'I visit profile design page' do
visit profile_design_path
visit design_profile_path
end
Given 'I visit profile history page' do
visit profile_history_path
end
Given 'I visit profile token page' do
visit profile_token_path
visit history_profile_path
end
# ----------------------------------------
......
......@@ -29,7 +29,16 @@ describe "Users Security" do
end
describe "GET /profile/account" do
subject { profile_account_path }
subject { account_profile_path }
it { should be_allowed_for @u1 }
it { should be_allowed_for :admin }
it { should be_allowed_for :user }
it { should be_denied_for :visitor }
end
describe "GET /profile/design" do
subject { design_profile_path }
it { should be_allowed_for @u1 }
it { should be_allowed_for :admin }
......
......@@ -82,37 +82,25 @@ end
# profile GET /profile(.:format) profile#show
# profile_design GET /profile/design(.:format) profile#design
# profile_update PUT /profile/update(.:format) profile#update
describe ProfileController, "routing" do
describe ProfilesController, "routing" do
it "to #account" do
get("/profile/account").should route_to('profile#account')
get("/profile/account").should route_to('profiles#account')
end
it "to #history" do
get("/profile/history").should route_to('profile#history')
end
it "to #password_update" do
put("/profile/password").should route_to('profile#password_update')
end
it "to #token" do
get("/profile/token").should route_to('profile#token')
get("/profile/history").should route_to('profiles#history')
end
it "to #reset_private_token" do
put("/profile/reset_private_token").should route_to('profile#reset_private_token')
put("/profile/reset_private_token").should route_to('profiles#reset_private_token')
end
it "to #show" do
get("/profile").should route_to('profile#show')
get("/profile").should route_to('profiles#show')
end
it "to #design" do
get("/profile/design").should route_to('profile#design')
end
it "to #update" do
put("/profile/update").should route_to('profile#update')
get("/profile/design").should route_to('profiles#design')
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment