Description:
modify user list creation into user list update
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r469:b28cd479ede6 - - 1 file changed: 11 inserted, 5 deleted
@@ -63,53 +63,59 | |||
|
63 | 63 | end |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def create_from_list |
|
67 | 67 | lines = params[:user_list] |
|
68 | 68 | |
|
69 | 69 | note = [] |
|
70 | 70 | |
|
71 | 71 | lines.split("\n").each do |line| |
|
72 | 72 | items = line.chomp.split(',') |
|
73 | 73 | if items.length>=2 |
|
74 | 74 | login = items[0] |
|
75 | 75 | full_name = items[1] |
|
76 | 76 | |
|
77 | 77 | added_random_password = false |
|
78 | 78 | if items.length>=3 |
|
79 | 79 | password = items[2].chomp(" ") |
|
80 | 80 | user_alias = (items.length>=4) ? items[3] : login |
|
81 | 81 | else |
|
82 | 82 | password = random_password |
|
83 | 83 | user_alias = (items.length>=4) ? items[3] : login |
|
84 | 84 | added_random_password = true |
|
85 | 85 | end |
|
86 | 86 | |
|
87 |
- user = User. |
|
|
88 | - :full_name => full_name, | |
|
89 | - :password => password, | |
|
90 |
- |
|
|
91 | - :alias => user_alias}) | |
|
87 | + user = User.find_by_login(login) | |
|
88 | + if (user) | |
|
89 | + user.full_name = full_name | |
|
90 | + user.password = password | |
|
91 | + else | |
|
92 | + user = User.new({:login => login, | |
|
93 | + :full_name => full_name, | |
|
94 | + :password => password, | |
|
95 | + :password_confirmation => password, | |
|
96 | + :alias => user_alias}) | |
|
97 | + end | |
|
92 | 98 | user.activated = true |
|
93 | 99 | user.save |
|
94 | 100 | |
|
95 | 101 | if added_random_password |
|
96 | 102 | note << "'#{login}' (+)" |
|
97 | 103 | else |
|
98 | 104 | note << login |
|
99 | 105 | end |
|
100 | 106 | end |
|
101 | 107 | end |
|
102 | 108 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
103 | 109 | ' were successfully created. ' + |
|
104 | 110 | '( (+) - created with random passwords.)' |
|
105 | 111 | redirect_to :action => 'list' |
|
106 | 112 | end |
|
107 | 113 | |
|
108 | 114 | def edit |
|
109 | 115 | @user = User.find(params[:id]) |
|
110 | 116 | end |
|
111 | 117 | |
|
112 | 118 | def update |
|
113 | 119 | @user = User.find(params[:id]) |
|
114 | 120 | if @user.update_attributes(params[:user]) |
|
115 | 121 | flash[:notice] = 'User was successfully updated.' |
You need to be logged in to leave comments.
Login now