Description:
add_email_to_user, fix empty problem for_in_place_editing git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@42 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

r18:d8813c40713d - - 5 files changed: 42 inserted, 4 deleted

@@ -0,0 +1,9
1 + class AddEmailToUsers < ActiveRecord::Migration
2 + def self.up
3 + add_column :users, :email, :string
4 + end
5 +
6 + def self.down
7 + remove_column :users, :email
8 + end
9 + end
@@ -1,21 +1,22
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 8 in_place_edit_for :user, :full_name
9 - in_place_edit_for :user, :alias
9 + in_place_edit_for :user, :alias_for_editing
10 + in_place_edit_for :user, :email_for_editing
10 11
11 12 def index
12 13 @user = User.find(session[:user_id])
13 14 end
14 15
15 16 def chg_passwd
16 17 user = User.find(session[:user_id])
17 18 user.password = params[:passwd]
18 19 user.password_confirmation = params[:passwd_verify]
19 20 if user.save
20 21 flash[:notice] = 'password changed'
21 22 else
@@ -19,25 +19,49
19 19 user = find_by_login(login)
20 20 return user if user && user.authenticated?(password)
21 21 end
22 22
23 23 def authenticated?(password)
24 24 hashed_password == encrypt(password,salt)
25 25 end
26 26
27 27 def admin?
28 28 self.roles.detect {|r| r.name == 'admin' }
29 29 end
30 30
31 - # protected
31 + def email_for_editing
32 + if self.email!=nil
33 + self.email
34 + else
35 + "unknown"
36 + end
37 + end
38 +
39 + def email_for_editing=(e)
40 + self.email=e
41 + end
42 +
43 + def alias_for_editing
44 + if self.alias!=nil
45 + self.alias
46 + else
47 + "unknown"
48 + end
49 + end
50 +
51 + def alias_for_editing=(e)
52 + self.alias=e
53 + end
54 +
55 + protected
32 56 def encrypt_new_password
33 57 return if password.blank?
34 58 self.salt = (10+rand(90)).to_s
35 59 self.hashed_password = encrypt(password,salt)
36 60 end
37 61
38 62 def password_required?
39 63 hashed_password.blank? || !password.blank?
40 64 end
41 65
42 66 def encrypt(string,salt)
43 67 Digest::SHA1.hexdigest(salt + string)
@@ -5,25 +5,28
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 14 %td.uinfo= in_place_editor_field :user, 'full_name', {}, :rows => 1
15 15 %tr
16 16 %th.uinfo Alias
17 - %td.uinfo= in_place_editor_field :user, 'alias', {}, :rows => 1
17 + %td.uinfo= in_place_editor_field :user, 'alias_for_editing', {}, :rows => 1
18 + %tr
19 + %th.uinfo E-mail
20 + %td.uinfo= in_place_editor_field :user, 'email_for_editing', {}, :rows => 1
18 21 %tr
19 22 %th.uinfo Password
20 23 %td.uinfo
21 24 - form_tag :action => 'chg_passwd', :method => 'post' do
22 25 %table
23 26 %tr
24 27 %td= password_field_tag 'passwd'
25 28 %td (new)
26 29 %tr
27 30 %td= password_field_tag 'passwd_verify'
28 31 %td (verify)
29 32 %tr
@@ -1,24 +1,24
1 1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 2 # please use the migrations feature of ActiveRecord to incrementally modify your database, and
3 3 # then regenerate this schema definition.
4 4 #
5 5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 6 # to create the application database on another system, you should be using db:schema:load, not running
7 7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12 - ActiveRecord::Schema.define(:version => 11) do
12 + ActiveRecord::Schema.define(:version => 12) do
13 13
14 14 create_table "languages", :force => true do |t|
15 15 t.string "name", :limit => 10
16 16 t.string "pretty_name"
17 17 t.string "ext", :limit => 10
18 18 end
19 19
20 20 create_table "problems", :force => true do |t|
21 21 t.string "name", :limit => 30
22 22 t.string "full_name"
23 23 t.integer "full_score"
24 24 t.date "date_added"
@@ -76,17 +76,18
76 76
77 77 create_table "tasks", :force => true do |t|
78 78 t.integer "submission_id"
79 79 t.datetime "created_at"
80 80 end
81 81
82 82 create_table "users", :force => true do |t|
83 83 t.string "login", :limit => 10
84 84 t.string "full_name"
85 85 t.string "hashed_password"
86 86 t.string "salt", :limit => 5
87 87 t.string "alias"
88 + t.string "email"
88 89 end
89 90
90 91 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
91 92
92 93 end
You need to be logged in to leave comments. Login now