|
@@ -532,4 +532,38 @@ class User extends Api
|
|
|
Sms::flush($mobile, 'changemobile');
|
|
|
$this->success();
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 修改邮箱
|
|
|
+ *
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string $email 邮箱
|
|
|
+ * @param string $captcha 验证码
|
|
|
+ */
|
|
|
+ public function changeemail()
|
|
|
+ {
|
|
|
+ $user = $this->auth->getUser();
|
|
|
+ $email = $this->request->post('email');
|
|
|
+ $captcha = $this->request->post('captcha');
|
|
|
+ if (!$email || !$captcha) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+ if (!Validate::is($email, "email")) {
|
|
|
+ $this->error(__('Email is incorrect'));
|
|
|
+ }
|
|
|
+ if (\app\common\model\User::where('email', $email)->where('id', '<>', $user->id)->find()) {
|
|
|
+ $this->error(__('Email already exists'));
|
|
|
+ }
|
|
|
+ $result = Ems::check($email, $captcha, 'changeemail');
|
|
|
+ if (!$result) {
|
|
|
+ $this->error(__('Captcha is incorrect'));
|
|
|
+ }
|
|
|
+ $verification = $user->verification;
|
|
|
+ $verification->email = 1;
|
|
|
+ $user->verification = $verification;
|
|
|
+ $user->email = $email;
|
|
|
+ $user->save();
|
|
|
+
|
|
|
+ Ems::flush($email, 'changeemail');
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
}
|