Description:
disable fullname editing git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@47 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r23:6beb043d888f - - 3 files changed: 12 inserted, 8 deleted

@@ -1,28 +1,27
1 1 class UsersController < ApplicationController
2 2
3 3 before_filter :authenticate
4 4
5 5 verify :method => :post, :only => [:chg_passwd],
6 6 :redirect_to => { :action => :index }
7 7
8 - in_place_edit_for :user, :full_name
9 8 in_place_edit_for :user, :alias_for_editing
10 9 in_place_edit_for :user, :email_for_editing
11 10
12 11 def index
13 12 @user = User.find(session[:user_id])
14 13 end
15 14
16 15 def chg_passwd
17 16 user = User.find(session[:user_id])
18 17 user.password = params[:passwd]
19 18 user.password_confirmation = params[:passwd_verify]
20 19 if user.save
21 20 flash[:notice] = 'password changed'
22 21 else
23 22 flash[:notice] = 'Error: password changing failed'
24 23 end
25 24 redirect_to :action => 'index'
26 25 end
27 26
28 27 end
@@ -1,69 +1,74
1 1 require 'digest/sha1'
2 2
3 3 class User < ActiveRecord::Base
4 4
5 5 has_and_belongs_to_many :roles
6 6
7 7 validates_presence_of :login
8 8 validates_presence_of :full_name
9 + validates_length_of :full_name, :minimum => 1
9 10
10 11 validates_presence_of :password, :if => :password_required?
11 12 validates_length_of :password, :within => 4..20, :if => :password_required?
12 13 validates_confirmation_of :password, :if => :password_required?
13 14
14 15 attr_accessor :password
15 16
16 17 before_save :encrypt_new_password
17 18
18 19 def self.authenticate(login, password)
19 20 user = find_by_login(login)
20 21 return user if user && user.authenticated?(password)
21 22 end
22 23
23 24 def authenticated?(password)
24 25 hashed_password == encrypt(password,salt)
25 26 end
26 27
27 28 def admin?
28 29 self.roles.detect {|r| r.name == 'admin' }
29 30 end
30 31
31 32 def email_for_editing
32 - if self.email!=nil
33 + if self.email==nil
34 + "(unknown)"
35 + elsif self.email==''
36 + "(blank)"
37 + else
33 38 self.email
34 - else
35 - "unknown"
36 39 end
37 40 end
38 41
39 42 def email_for_editing=(e)
40 43 self.email=e
41 44 end
42 45
43 46 def alias_for_editing
44 - if self.alias!=nil
47 + if self.alias==nil
48 + "(unknown)"
49 + elsif self.alias==''
50 + "(blank)"
51 + else
45 52 self.alias
46 - else
47 - "unknown"
48 53 end
49 54 end
50 55
51 56 def alias_for_editing=(e)
52 57 self.alias=e
53 58 end
54 59
55 60 protected
56 61 def encrypt_new_password
57 62 return if password.blank?
58 63 self.salt = (10+rand(90)).to_s
59 64 self.hashed_password = encrypt(password,salt)
60 65 end
61 66
62 67 def password_required?
63 68 hashed_password.blank? || !password.blank?
64 69 end
65 70
66 71 def encrypt(string,salt)
67 72 Digest::SHA1.hexdigest(salt + string)
68 73 end
69 74 end
@@ -1,35 +1,35
1 1
2 2 %h1 Your account settings
3 3
4 4 %p
5 5 You can edit your full name and alias. Just click on the text and edit it.
6 6
7 7
8 8 %table.uinfo
9 9 %tr
10 10 %th.uinfo Login
11 11 %td.uinfo= @user.login
12 12 %tr
13 13 %th.uinfo Full name
14 - %td.uinfo= in_place_editor_field :user, 'full_name', {}, :rows => 1
14 + %td.uinfo= @user.full_name
15 15 %tr
16 16 %th.uinfo Alias
17 17 %td.uinfo= in_place_editor_field :user, 'alias_for_editing', {}, :rows => 1
18 18 %tr
19 19 %th.uinfo E-mail
20 20 %td.uinfo= in_place_editor_field :user, 'email_for_editing', {}, :rows => 1
21 21 %tr
22 22 %th.uinfo Password
23 23 %td.uinfo
24 24 - form_tag :action => 'chg_passwd', :method => 'post' do
25 25 %table
26 26 %tr
27 27 %td= password_field_tag 'passwd'
28 28 %td (new)
29 29 %tr
30 30 %td= password_field_tag 'passwd_verify'
31 31 %td (verify)
32 32 %tr
33 33 %td{:colspan => "2"}
34 34 = submit_tag 'change password'
35 35
You need to be logged in to leave comments. Login now