lizhen_gitee пре 1 година
родитељ
комит
c48a2568ec
2 измењених фајлова са 15 додато и 23 уклоњено
  1. 1 1
      application/api/controller/company/User.php
  2. 14 22
      application/common/library/Authcompany.php

+ 1 - 1
application/api/controller/company/User.php

@@ -99,7 +99,7 @@ class User extends Apic
 
         //模拟一次登录
         $this->auth->direct($user->id);
-        $ret = $this->auth->changepwd($newpassword, '', true);
+        $ret = $this->auth->resetpwd($newpassword, '', true);
         if ($ret) {
             $this->success(__('Reset password successful'));
         } else {

+ 14 - 22
application/common/library/Authcompany.php

@@ -206,34 +206,26 @@ class Authcompany
      * @param bool   $ignoreoldpassword 忽略旧密码
      * @return boolean
      */
-    public function changepwd($newpassword, $oldpassword = '', $ignoreoldpassword = false)
+    public function resetpwd($newpassword)
     {
         if (!$this->_logined) {
             $this->setError('You are not logged in');
             return false;
         }
-        //判断旧密码是否正确
-        if ($this->_user->password == $this->getEncryptPassword($oldpassword, $this->_user->salt) || $ignoreoldpassword) {
-            Db::startTrans();
-            try {
-                $salt = Random::alnum();
-                $newpassword = $this->getEncryptPassword($newpassword, $salt);
-                $this->_user->save(['loginfailure' => 0, 'password' => $newpassword, 'salt' => $salt]);
 
-                Tokencompany::delete($this->_token);
-                //修改密码成功的事件
-                Hook::listen("company_changepwd_successed", $this->_user);
-                Db::commit();
-            } catch (Exception $e) {
-                Db::rollback();
-                $this->setError($e->getMessage());
-                return false;
-            }
-            return true;
-        } else {
-            $this->setError('Password is incorrect');
-            return false;
-        }
+        Db::startTrans();
+
+        $salt = Random::alnum();
+        $newpassword = $this->getEncryptPassword($newpassword, $salt);
+        unset($this->_user['company']);
+        $this->_user->save(['password' => $newpassword, 'salt' => $salt]);
+
+        Tokencompany::delete($this->_token);
+
+        Db::commit();
+
+        return true;
+
     }
 
     /**