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