@@ -114,73 +114,76 @@ public function editAction()
114
114
115
115
public function saveAction ()
116
116
{
117
- if ($ data = $ this ->getRequest ()->getPost ()) {
118
- $ id = $ this ->getRequest ()->getParam ('user_id ' );
119
- $ model = Mage::getModel ('admin/user ' )->load ($ id );
120
- // @var $isNew flag for detecting new admin user creation.
121
- $ isNew = !$ model ->getId () ? true : false ;
122
- if (!$ model ->getId () && $ id ) {
123
- Mage::getSingleton ('adminhtml/session ' )->addError ($ this ->__ ('This user no longer exists. ' ));
124
- $ this ->_redirect ('*/*/ ' );
125
- return ;
126
- }
117
+ $ data = $ this ->getRequest ()->getPost ();
127
118
128
- //Validate current admin password
129
- $ currentPassword = $ this ->getRequest ()->getParam ('current_password ' , null );
130
- $ this ->getRequest ()->setParam ('current_password ' , null );
131
- unset($ data ['current_password ' ]);
132
- $ result = $ this ->_validateCurrentPassword ($ currentPassword );
119
+ if (!$ data ) {
120
+ $ this ->_redirect ('*/*/ ' );
121
+ return ;
122
+ }
133
123
134
- $ model ->setData ($ data );
124
+ $ id = $ this ->getRequest ()->getParam ('user_id ' );
125
+ $ role = $ this ->getRequest ()->getParam ('role ' );
135
126
136
- /*
137
- * Unsetting new password and password confirmation if they are blank
138
- */
139
- if ($ model ->hasNewPassword () && $ model ->getNewPassword () === '' ) {
140
- $ model ->unsNewPassword ();
141
- }
142
- if ($ model ->hasPasswordConfirmation () && $ model ->getPasswordConfirmation () === '' ) {
143
- $ model ->unsPasswordConfirmation ();
144
- }
127
+ $ user = Mage::getModel ('admin/user ' )->load ($ id );
128
+ $ isNew = $ user ->isObjectNew ();
129
+
130
+ if ($ id && !$ user ->getId ()) {
131
+ $ this ->_getSession ()->addError ($ this ->__ ('This user no longer exists. ' ));
132
+ $ this ->_redirect ('*/*/ ' );
133
+ return ;
134
+ }
135
+
136
+ $ currentPassword = $ this ->getRequest ()->getParam ('current_password ' );
137
+ $ this ->getRequest ()->setParam ('current_password ' , null );
138
+ unset($ data ['current_password ' ]);
139
+ $ result = $ this ->_validateCurrentPassword ($ currentPassword );
140
+
141
+ $ user ->setData ($ data );
145
142
146
- if (!is_array ($ result )) {
147
- $ result = $ model ->validate ();
143
+ /*
144
+ * Unsetting new password and password confirmation if they are blank
145
+ */
146
+ if ($ user ->hasNewPassword () && $ user ->getNewPassword () === '' ) {
147
+ $ user ->unsNewPassword ();
148
+ }
149
+ if ($ user ->hasPasswordConfirmation () && $ user ->getPasswordConfirmation () === '' ) {
150
+ $ user ->unsPasswordConfirmation ();
151
+ }
152
+
153
+ if (!is_array ($ result )) {
154
+ $ result = $ user ->validate ();
155
+ }
156
+
157
+ if (is_array ($ result )) {
158
+ $ this ->_getSession ()->setUserData ($ data );
159
+ foreach ($ result as $ message ) {
160
+ $ this ->_getSession ()->addError ($ message );
148
161
}
149
- if (is_array ($ result )) {
150
- Mage::getSingleton ('adminhtml/session ' )->setUserData ($ data );
151
- foreach ($ result as $ message ) {
152
- Mage::getSingleton ('adminhtml/session ' )->addError ($ message );
153
- }
154
- $ this ->_redirect ('*/*/edit ' , ['_current ' => true ]);
155
- return $ this ;
162
+ $ this ->_redirect ('*/*/edit ' , ['_current ' => true ]);
163
+ return ;
164
+ }
165
+
166
+ try {
167
+ $ user ->save ();
168
+
169
+ // Send notification to General and additional contacts (if declared) that a new admin user was created.
170
+ if (Mage::getStoreConfigFlag ('admin/security/crate_admin_user_notification ' ) && $ isNew ) {
171
+ Mage::getModel ('admin/user ' )->sendAdminNotification ($ user );
156
172
}
157
173
158
- try {
159
- $ model ->save ();
160
- // Send notification to General and additional contacts (if declared) that a new admin user was created.
161
- if (Mage::getStoreConfigFlag ('admin/security/crate_admin_user_notification ' ) && $ isNew ) {
162
- Mage::getModel ('admin/user ' )->sendAdminNotification ($ model );
163
- }
164
- if ($ uRoles = $ this ->getRequest ()->getParam ('roles ' , false )) {
165
- if (is_array ($ uRoles ) && (count ($ uRoles ) >= 1 )) {
166
- // with fix for previous multi-roles logic
167
- $ model ->setRoleIds (array_slice ($ uRoles , 0 , 1 ))
168
- ->setRoleUserId ($ model ->getUserId ())
169
- ->saveRelations ();
170
- }
171
- }
172
- Mage::getSingleton ('adminhtml/session ' )->addSuccess ($ this ->__ ('The user has been saved. ' ));
173
- Mage::getSingleton ('adminhtml/session ' )->setUserData (false );
174
- $ this ->_redirect ('*/*/ ' );
175
- return ;
176
- } catch (Mage_Core_Exception $ e ) {
177
- Mage::getSingleton ('adminhtml/session ' )->addError ($ e ->getMessage ());
178
- Mage::getSingleton ('adminhtml/session ' )->setUserData ($ data );
179
- $ this ->_redirect ('*/*/edit ' , ['user_id ' => $ model ->getUserId ()]);
180
- return ;
174
+ if ($ role ) {
175
+ $ user ->setRoleId ((int )$ role )
176
+ ->setRoleUserId ($ user ->getUserId ())
177
+ ->saveRelations ();
181
178
}
179
+ $ this ->_getSession ()->addSuccess ($ this ->__ ('The user has been saved. ' ));
180
+ $ this ->_getSession ()->setUserData (false );
181
+ $ this ->_redirect ('*/*/ ' );
182
+ } catch (Mage_Core_Exception $ e ) {
183
+ $ this ->_getSession ()->addError ($ e ->getMessage ());
184
+ $ this ->_getSession ()->setUserData ($ data );
185
+ $ this ->_redirect ('*/*/edit ' , ['user_id ' => $ user ->getUserId ()]);
182
186
}
183
- $ this ->_redirect ('*/*/ ' );
184
187
}
185
188
186
189
public function deleteAction ()
0 commit comments