Commit ffec158de4c6a78dfa17ae0063d8f796c21a58c8
1 parent
4c8224ae
Exists in
master
and in
4 other branches
Restyle Profile#Account page
Showing
6 changed files
with
81 additions
and
176 deletions
Show diff stats
app/assets/stylesheets/common.scss
app/controllers/profiles_controller.rb
| ... | ... | @@ -2,7 +2,6 @@ class ProfilesController < ApplicationController |
| 2 | 2 | include ActionView::Helpers::SanitizeHelper |
| 3 | 3 | |
| 4 | 4 | before_filter :user |
| 5 | - before_filter :authorize_change_password!, only: :update_password | |
| 6 | 5 | before_filter :authorize_change_username!, only: :update_username |
| 7 | 6 | |
| 8 | 7 | layout 'profile' |
| ... | ... | @@ -13,9 +12,6 @@ class ProfilesController < ApplicationController |
| 13 | 12 | def design |
| 14 | 13 | end |
| 15 | 14 | |
| 16 | - def account | |
| 17 | - end | |
| 18 | - | |
| 19 | 15 | def update |
| 20 | 16 | if @user.update_attributes(params[:user]) |
| 21 | 17 | flash[:notice] = "Profile was successfully updated" |
| ... | ... | @@ -29,33 +25,12 @@ class ProfilesController < ApplicationController |
| 29 | 25 | end |
| 30 | 26 | end |
| 31 | 27 | |
| 32 | - def token | |
| 33 | - end | |
| 34 | - | |
| 35 | - def update_password | |
| 36 | - password_attributes = params[:user].select do |key, value| | |
| 37 | - %w(password password_confirmation).include?(key.to_s) | |
| 38 | - end | |
| 39 | - | |
| 40 | - unless @user.valid_password?(params[:user][:current_password]) | |
| 41 | - redirect_to account_profile_path, alert: 'You must provide a valid current password' | |
| 42 | - return | |
| 43 | - end | |
| 44 | - | |
| 45 | - if @user.update_attributes(password_attributes) | |
| 46 | - flash[:notice] = "Password was successfully updated. Please login with it" | |
| 47 | - redirect_to new_user_session_path | |
| 48 | - else | |
| 49 | - render 'account' | |
| 50 | - end | |
| 51 | - end | |
| 52 | - | |
| 53 | 28 | def reset_private_token |
| 54 | 29 | if current_user.reset_authentication_token! |
| 55 | 30 | flash[:notice] = "Token was successfully updated" |
| 56 | 31 | end |
| 57 | 32 | |
| 58 | - redirect_to account_profile_path | |
| 33 | + redirect_to profile_account_path | |
| 59 | 34 | end |
| 60 | 35 | |
| 61 | 36 | def history |
| ... | ... | @@ -76,10 +51,6 @@ class ProfilesController < ApplicationController |
| 76 | 51 | @user = current_user |
| 77 | 52 | end |
| 78 | 53 | |
| 79 | - def authorize_change_password! | |
| 80 | - return render_404 if @user.ldap_user? | |
| 81 | - end | |
| 82 | - | |
| 83 | 54 | def authorize_change_username! |
| 84 | 55 | return render_404 unless @user.can_change_username? |
| 85 | 56 | end | ... | ... |
app/views/layouts/nav/_profile.html.haml
| ... | ... | @@ -2,8 +2,11 @@ |
| 2 | 2 | = nav_link(path: 'profiles#show', html_options: {class: 'home'}) do |
| 3 | 3 | = link_to profile_path, title: "Profile" do |
| 4 | 4 | %i.icon-home |
| 5 | - = nav_link(path: 'profiles#account') do | |
| 6 | - = link_to "Account", account_profile_path | |
| 5 | + = nav_link(controller: :accounts) do | |
| 6 | + = link_to "Account", profile_account_path | |
| 7 | + - unless current_user.ldap_user? | |
| 8 | + = nav_link(controller: :passwords) do | |
| 9 | + = link_to "Password", edit_profile_password_path | |
| 7 | 10 | = nav_link(controller: :notifications) do |
| 8 | 11 | = link_to "Notifications", profile_notifications_path |
| 9 | 12 | = nav_link(controller: :keys) do | ... | ... |
app/views/profiles/account.html.haml
| ... | ... | @@ -1,141 +0,0 @@ |
| 1 | -%h3.page-title | |
| 2 | - Account settings | |
| 3 | -%p.light | |
| 4 | - You can change your password, username and private token here. | |
| 5 | - - if current_user.ldap_user? | |
| 6 | - Some options are unavailable for LDAP accounts | |
| 7 | -%hr | |
| 8 | - | |
| 9 | - | |
| 10 | -.row | |
| 11 | - .span2 | |
| 12 | - %ul.nav.nav-pills.nav-stacked.nav-stacked-menu | |
| 13 | - %li.active | |
| 14 | - = link_to '#tab-token', 'data-toggle' => 'tab' do | |
| 15 | - Private Token | |
| 16 | - %li | |
| 17 | - = link_to '#tab-password', 'data-toggle' => 'tab' do | |
| 18 | - Password | |
| 19 | - | |
| 20 | - - if show_profile_social_tab? | |
| 21 | - %li | |
| 22 | - = link_to '#tab-social', 'data-toggle' => 'tab' do | |
| 23 | - Social Accounts | |
| 24 | - | |
| 25 | - - if show_profile_username_tab? | |
| 26 | - %li | |
| 27 | - = link_to '#tab-username', 'data-toggle' => 'tab' do | |
| 28 | - Change Username | |
| 29 | - | |
| 30 | - - if show_profile_remove_tab? | |
| 31 | - %li | |
| 32 | - = link_to '#tab-remove', 'data-toggle' => 'tab' do | |
| 33 | - Remove Account | |
| 34 | - .span10 | |
| 35 | - .tab-content | |
| 36 | - .tab-pane.active#tab-token | |
| 37 | - %fieldset.update-token | |
| 38 | - %legend | |
| 39 | - Private token | |
| 40 | - %span.cred.pull-right | |
| 41 | - keep it secret! | |
| 42 | - %div | |
| 43 | - = form_for @user, url: reset_private_token_profile_path, method: :put do |f| | |
| 44 | - .data | |
| 45 | - %p.slead | |
| 46 | - Your private token is used to access application resources without authentication. | |
| 47 | - %br | |
| 48 | - It can be used for atom feeds or the API. | |
| 49 | - %p.cgray | |
| 50 | - - if current_user.private_token | |
| 51 | - = text_field_tag "token", current_user.private_token, class: "input-xxlarge large_text input-xpadding" | |
| 52 | - = f.submit 'Reset', confirm: "Are you sure?", class: "btn btn-primary btn-build-token" | |
| 53 | - - else | |
| 54 | - %span You don`t have one yet. Click generate to fix it. | |
| 55 | - = f.submit 'Generate', class: "btn success btn-build-token" | |
| 56 | - | |
| 57 | - .tab-pane#tab-password | |
| 58 | - %fieldset.update-password | |
| 59 | - %legend Password | |
| 60 | - - if current_user.ldap_user? | |
| 61 | - %h3.nothing_here_message Not available for LDAP user | |
| 62 | - - else | |
| 63 | - = form_for @user, url: update_password_profile_path, method: :put do |f| | |
| 64 | - %div | |
| 65 | - %p.slead | |
| 66 | - You must provide current password in order to change it. | |
| 67 | - %br | |
| 68 | - After a successful password update you will be redirected to login page where you should login with your new password | |
| 69 | - -if @user.errors.any? | |
| 70 | - .alert.alert-error | |
| 71 | - %ul | |
| 72 | - - @user.errors.full_messages.each do |msg| | |
| 73 | - %li= msg | |
| 74 | - .control-group | |
| 75 | - = f.label :current_password, class: 'cgreen' | |
| 76 | - .controls= f.password_field :current_password, required: true | |
| 77 | - .control-group | |
| 78 | - = f.label :password, 'New password' | |
| 79 | - .controls= f.password_field :password, required: true | |
| 80 | - .control-group | |
| 81 | - = f.label :password_confirmation | |
| 82 | - .controls | |
| 83 | - = f.password_field :password_confirmation, required: true | |
| 84 | - .control-group | |
| 85 | - .controls | |
| 86 | - = f.submit 'Save password', class: "btn btn-save" | |
| 87 | - | |
| 88 | - - if show_profile_social_tab? | |
| 89 | - .tab-pane#tab-social | |
| 90 | - %fieldset | |
| 91 | - %legend Social Accounts | |
| 92 | - .oauth_select_holder | |
| 93 | - %p.hint Tip: Click on icon to activate signin with one of the following services | |
| 94 | - - enabled_social_providers.each do |provider| | |
| 95 | - %span{class: oauth_active_class(provider) } | |
| 96 | - = link_to authbutton(provider, 32), omniauth_authorize_path(User, provider) | |
| 97 | - | |
| 98 | - - if show_profile_username_tab? | |
| 99 | - .tab-pane#tab-username | |
| 100 | - %fieldset.update-username | |
| 101 | - %legend | |
| 102 | - Username | |
| 103 | - %small.cred.pull-right | |
| 104 | - Changing your username can have unintended side effects! | |
| 105 | - = form_for @user, url: update_username_profile_path, method: :put, remote: true do |f| | |
| 106 | - %div | |
| 107 | - .control-group | |
| 108 | - = f.label :username | |
| 109 | - .controls | |
| 110 | - = f.text_field :username, required: true | |
| 111 | - | |
| 112 | - %span.loading-gif.hide= image_tag "ajax_loader.gif" | |
| 113 | - %span.update-success.cgreen.hide | |
| 114 | - %i.icon-ok | |
| 115 | - Saved | |
| 116 | - %span.update-failed.cred.hide | |
| 117 | - %i.icon-remove | |
| 118 | - Failed | |
| 119 | - %ul.cred | |
| 120 | - %li This will change the web URL for personal projects. | |
| 121 | - %li This will change the git path to repositories for personal projects. | |
| 122 | - .controls | |
| 123 | - = f.submit 'Save username', class: "btn btn-save" | |
| 124 | - | |
| 125 | - - if show_profile_remove_tab? | |
| 126 | - .tab-pane#tab-remove | |
| 127 | - %fieldset.remove-account | |
| 128 | - %legend | |
| 129 | - Remove account | |
| 130 | - %div | |
| 131 | - %p Deleting an account has the following effects: | |
| 132 | - %ul | |
| 133 | - %li All user content like authored issues, snippets, comments will be removed | |
| 134 | - - rp = current_user.personal_projects.count | |
| 135 | - - unless rp.zero? | |
| 136 | - %li #{pluralize rp, 'personal project'} will be removed and cannot be restored | |
| 137 | - - if current_user.solo_owned_groups.present? | |
| 138 | - %li | |
| 139 | - Next groups will be abandoned. You should transfer or remove them: | |
| 140 | - %strong #{current_user.solo_owned_groups.map(&:name).join(', ')} | |
| 141 | - = link_to 'Delete account', user_registration_path, confirm: "REMOVE #{current_user.name}? Are you sure?", method: :delete, class: "btn btn-remove" |
| ... | ... | @@ -0,0 +1,73 @@ |
| 1 | +%h3.page-title | |
| 2 | + Account settings | |
| 3 | +%p.light | |
| 4 | + You can change your username and private token here. | |
| 5 | + - if current_user.ldap_user? | |
| 6 | + Some options are unavailable for LDAP accounts | |
| 7 | +%hr | |
| 8 | + | |
| 9 | + | |
| 10 | +%div | |
| 11 | + %fieldset.update-token | |
| 12 | + %legend | |
| 13 | + Private token | |
| 14 | + %div | |
| 15 | + = form_for @user, url: reset_private_token_profile_path, method: :put do |f| | |
| 16 | + .data | |
| 17 | + %p | |
| 18 | + Your private token is used to access application resources without authentication. | |
| 19 | + %br | |
| 20 | + It can be used for atom feeds or the API. | |
| 21 | + %span.cred | |
| 22 | + Keep it secret! | |
| 23 | + | |
| 24 | + %p.cgray | |
| 25 | + - if current_user.private_token | |
| 26 | + = text_field_tag "token", current_user.private_token, class: "input-xlarge input-xpadding pull-left" | |
| 27 | + = f.submit 'Reset', confirm: "Are you sure?", class: "btn btn-primary btn-build-token prepend-left-10" | |
| 28 | + - else | |
| 29 | + %span You don`t have one yet. Click generate to fix it. | |
| 30 | + = f.submit 'Generate', class: "btn success btn-build-token" | |
| 31 | + | |
| 32 | + | |
| 33 | + - if show_profile_social_tab? | |
| 34 | + %fieldset | |
| 35 | + %legend Social Accounts | |
| 36 | + .oauth_select_holder | |
| 37 | + %p Click on icon to activate signin with one of the following services | |
| 38 | + - enabled_social_providers.each do |provider| | |
| 39 | + %span{class: oauth_active_class(provider) } | |
| 40 | + = link_to authbutton(provider, 32), omniauth_authorize_path(User, provider) | |
| 41 | + | |
| 42 | + - if show_profile_username_tab? | |
| 43 | + %fieldset.update-username | |
| 44 | + %legend | |
| 45 | + Username | |
| 46 | + = form_for @user, url: update_username_profile_path, method: :put, remote: true do |f| | |
| 47 | + %p | |
| 48 | + Changing your username will change path to all personl projects! | |
| 49 | + %div | |
| 50 | + = f.text_field :username, required: true, class: 'input-xlarge input-xpadding' | |
| 51 | + | |
| 52 | + %span.loading-gif.hide= image_tag "ajax_loader.gif" | |
| 53 | + %p.light | |
| 54 | + = user_url(@user) | |
| 55 | + %div | |
| 56 | + = f.submit 'Save username', class: "btn btn-save" | |
| 57 | + | |
| 58 | + - if show_profile_remove_tab? | |
| 59 | + %fieldset.remove-account | |
| 60 | + %legend | |
| 61 | + Remove account | |
| 62 | + %div | |
| 63 | + %p Deleting an account has the following effects: | |
| 64 | + %ul | |
| 65 | + %li All user content like authored issues, snippets, comments will be removed | |
| 66 | + - rp = current_user.personal_projects.count | |
| 67 | + - unless rp.zero? | |
| 68 | + %li #{pluralize rp, 'personal project'} will be removed and cannot be restored | |
| 69 | + - if current_user.solo_owned_groups.present? | |
| 70 | + %li | |
| 71 | + Next groups will be abandoned. You should transfer or remove them: | |
| 72 | + %strong #{current_user.solo_owned_groups.map(&:name).join(', ')} | |
| 73 | + = link_to 'Delete account', user_registration_path, confirm: "REMOVE #{current_user.name}? Are you sure?", method: :delete, class: "btn btn-remove" | ... | ... |
app/views/profiles/update_username.js.haml
| 1 | 1 | - if @user.valid? |
| 2 | 2 | :plain |
| 3 | - $('.update-username .update-success').show(); | |
| 3 | + new Flash("Username sucessfully changed", "notice") | |
| 4 | 4 | - else |
| 5 | 5 | :plain |
| 6 | - $('.update-username .update-failed').show(); | |
| 6 | + new Flash("Username change failed - #{@user.errors.full_messages.first}", "alert") | ... | ... |