Description:
fix user profile, add test
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r759:6c24fe0db627 - - 7 files changed: 76 inserted, 55 deleted
@@ -14,7 +14,6 | |||||
|
14 | :register, |
|
14 | :register, |
|
15 | :forget, |
|
15 | :forget, |
|
16 | :retrieve_password] |
|
16 | :retrieve_password] |
|
17 | - before_action :check_valid_login, :profile_authorization, only: [:profile] |
|
||
|
18 |
|
17 | ||
|
19 | before_action :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable] |
|
18 | before_action :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable] |
|
20 |
|
19 | ||
@@ -30,16 +29,25 | |||||
|
30 | end |
|
29 | end |
|
31 | end |
|
30 | end |
|
32 |
|
31 | ||
|
|
32 | + # edit logged in user profile | ||
|
|
33 | + def profile | ||
|
|
34 | + if !GraderConfiguration['system.user_setting_enabled'] | ||
|
|
35 | + redirect_to :controller => 'main', :action => 'list' | ||
|
|
36 | + else | ||
|
|
37 | + @user = current_user; | ||
|
|
38 | + end | ||
|
|
39 | + end | ||
|
|
40 | + | ||
|
33 | def chg_passwd |
|
41 | def chg_passwd |
|
34 | user = User.find(session[:user_id]) |
|
42 | user = User.find(session[:user_id]) |
|
35 | - user.password = params[:passwd] |
|
43 | + user.password = params[:password] |
|
36 |
- user.password_confirmation = params[:passw |
|
44 | + user.password_confirmation = params[:password_confirmation] |
|
37 | if user.save |
|
45 | if user.save |
|
38 | flash[:notice] = 'password changed' |
|
46 | flash[:notice] = 'password changed' |
|
39 | else |
|
47 | else |
|
40 | flash[:notice] = 'Error: password changing failed' |
|
48 | flash[:notice] = 'Error: password changing failed' |
|
41 | end |
|
49 | end |
|
42 |
- redirect_to :action => ' |
|
50 | + redirect_to :action => 'profile' |
|
43 | end |
|
51 | end |
|
44 |
|
52 | ||
|
45 | def new |
|
53 | def new |
@@ -215,5 +223,4 | |||||
|
215 | def user_params |
|
223 | def user_params |
|
216 | params.require(:user).permit(:login, :full_name, :email) |
|
224 | params.require(:user).permit(:login, :full_name, :email) |
|
217 | end |
|
225 | end |
|
218 | - |
|
||
|
219 | end |
|
226 | end |
@@ -74,7 +74,7 | |||||
|
74 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') |
|
74 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') |
|
75 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-comment')}".html_safe, 'messages', 'index', {title: I18n.t('menu.messages'), data: {toggle: 'tooltip'}}) |
|
75 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-comment')}".html_safe, 'messages', 'index', {title: I18n.t('menu.messages'), data: {toggle: 'tooltip'}}) |
|
76 | - if GraderConfiguration['system.user_setting_enabled'] |
|
76 | - if GraderConfiguration['system.user_setting_enabled'] |
|
77 |
- = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog')}".html_safe, 'users', ' |
|
77 | + = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog', id: 'user_profile')}".html_safe, 'users', 'profile', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) |
|
78 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{@current_user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) |
|
78 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{@current_user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) |
|
79 |
|
79 | ||
|
80 | / |
|
80 | / |
@@ -1,14 +1,12 | |||||
|
1 | = simple_form_for(@user) do |f| |
|
1 | = simple_form_for(@user) do |f| |
|
2 | = f.error_notification |
|
2 | = f.error_notification |
|
3 | - .row |
|
3 | + = f.input :login, label: 'Login' |
|
4 | - .col-md-6.col-md-offset-2 |
|
4 | + = f.input :full_name, label: 'Full name' |
|
5 | - = f.input :login, label: 'Login' |
|
5 | + = f.input :password |
|
6 | - = f.input :full_name, label: 'Full name' |
|
6 | + = f.input :password_confirmation |
|
7 |
- |
|
7 | + = f.input :email |
|
8 | - = f.input :password_confirmation |
|
8 | + = f.input :alias |
|
9 |
- |
|
9 | + = f.input :remark |
|
10 | - = f.input :alias |
|
10 | + = f.button :submit, class: 'btn btn-primary' |
|
11 | - = f.input :remark |
|
11 | + = link_to 'Cancel', :back, class: 'btn btn-default' |
|
12 | - = f.button :submit, class: 'btn btn-success' |
|
||
|
13 | - = link_to 'Cancel', :back, class: 'btn btn-default' |
|
||
|
14 |
|
12 |
@@ -1,4 +1,9 | |||||
|
1 | - %h1 Editing user |
|
1 | + .container-fluid |
|
2 | - = simple_form_for @user, url: user_admin_path(@user) do |f| |
|
2 | + .row |
|
3 | - = render partial: 'form', local: f |
|
3 | + .col-md-6 |
|
|
4 | + %h1 Editing user | ||
|
|
5 | + .row | ||
|
|
6 | + .col-md-6 | ||
|
|
7 | + = simple_form_for @user, url: user_admin_path(@user) do |f| | ||
|
|
8 | + = render partial: 'form', local: f | ||
|
4 |
|
9 |
@@ -1,36 +1,24 | |||||
|
1 | - = user_title_bar(@user) |
|
||
|
2 | - |
|
||
|
3 | - %h1 Your account settings |
|
||
|
4 | - |
|
||
|
5 | - -#%p |
|
||
|
6 | - -#You can edit your alias and e-mails. Just click on the text and edit it. |
|
||
|
7 |
|
|
1 | |
|
8 | - %table.table.table-bordered{:style => "width:30%"} |
|
2 | + .container-fluid |
|
9 | - %tr |
|
3 | + = form_tag :action => 'chg_passwd', :method => 'post' do |
|
10 | - %th Login |
|
4 | + .row |
|
11 | - %td= @user.login |
|
5 | + .col-md-6 |
|
12 | - %tr |
|
6 | + %h1 Your account settings |
|
13 | - %th Full name |
|
7 | + .form-group |
|
14 | - %td= @user.full_name |
|
8 | + %label{:for => "login"} Login |
|
15 | - -#%tr |
|
9 | + =@user.login |
|
16 | - -#%th.uinfo Alias |
|
10 | + .form-group |
|
17 | - -#%td.uinfo= in_place_editor_field :user, 'alias_for_editing', {}, :rows => 1 |
|
11 | + %label{:for => "full_name"} Full name |
|
18 | - -#%tr |
|
12 | + =@user.full_name |
|
19 | - -#%th.uinfo E-mail |
|
13 | + .form-group |
|
20 | - -#%td.uinfo= in_place_editor_field :user, 'email_for_editing', {}, :rows => 1 |
|
14 | + %label{:for => "password"} Password |
|
21 | - %tr |
|
15 | + =password_field_tag :password, nil, class: 'form-control' |
|
22 | - %th Password |
|
16 | + .form-group |
|
23 | - %td |
|
17 | + %label{:for => "password_confirmation"} Password confirmation |
|
24 | - = form_tag :action => 'chg_passwd', :method => 'post' do |
|
18 | + =password_field_tag :password_confirmation, nil, class: 'form-control' |
|
25 | - %table |
|
19 | + .row |
|
26 | - %tr |
|
20 | + .col-md-6 |
|
27 | - %td |
|
21 | + =submit_tag 'Edit', class: 'btn btn-primary' |
|
28 | - %input{:type => "password", :class => "form-control", :name => "passwd", :id => "passwd"} |
|
22 | + |
|
29 | - %td (new) |
|
23 | + |
|
30 | - %tr |
|
24 | + |
|
31 | - %td |
|
||
|
32 | - %input{:type => "password", :class => "form-control", :name => "passwd_verify", :id => "passwd_verify"} |
|
||
|
33 | - %td (verify) |
|
||
|
34 | - %tr |
|
||
|
35 | - %td{:colspan => "2"} |
|
||
|
36 | - %input{:type => "button", :class => "btn btn-default", :name => "commit", :value => "Change Password"} |
|
@@ -72,6 +72,10 | |||||
|
72 | get 'toggle_activate', 'toggle_enable' |
|
72 | get 'toggle_activate', 'toggle_enable' |
|
73 | get 'stat' |
|
73 | get 'stat' |
|
74 | end |
|
74 | end |
|
|
75 | + collection do | ||
|
|
76 | + get 'profile' | ||
|
|
77 | + post 'chg_passwd' | ||
|
|
78 | + end | ||
|
75 | end |
|
79 | end |
|
76 |
|
80 | ||
|
77 | resources :submissions do |
|
81 | resources :submissions do |
@@ -93,6 +93,25 | |||||
|
93 | assert_current_path login_main_path |
|
93 | assert_current_path login_main_path |
|
94 | end |
|
94 | end |
|
95 |
|
95 | ||
|
|
96 | + test "login then change password" do | ||
|
|
97 | + newpassword = '1234asdf' | ||
|
|
98 | + login 'john', 'hello' | ||
|
|
99 | + visit profile_users_path | ||
|
|
100 | + | ||
|
|
101 | + fill_in 'password', with: newpassword | ||
|
|
102 | + fill_in 'password_confirmation', with: newpassword | ||
|
|
103 | + | ||
|
|
104 | + click_on 'Edit' | ||
|
|
105 | + | ||
|
|
106 | + visit logout_main_path | ||
|
|
107 | + login 'john', 'hello' | ||
|
|
108 | + assert_text 'Wrong password' | ||
|
|
109 | + | ||
|
|
110 | + login 'john', newpassword | ||
|
|
111 | + assert_text "MAIN" | ||
|
|
112 | + assert_text "Submission" | ||
|
|
113 | + end | ||
|
|
114 | + | ||
|
96 | def login(username,password) |
|
115 | def login(username,password) |
|
97 | visit root_path |
|
116 | visit root_path |
|
98 | fill_in "Login", with: username |
|
117 | fill_in "Login", with: username |
You need to be logged in to leave comments.
Login now