Skip to content

Commit

Permalink
Merge pull request #94 from sendya/dev
Browse files Browse the repository at this point in the history
Update re send verification code
  • Loading branch information
sendya committed May 12, 2016
2 parents 1280ad1 + ae53f87 commit e0100d0
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
39 changes: 38 additions & 1 deletion Library/Controller/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,43 @@ public function register()
return $result;
}

/**
* 重发校验码
* @JSON
* @Authorization
*/
public function resend()
{
if($_POST['auth'] == 'y') {
$user = User::getCurrent();

$code = Utils::randomChar(10);
$forgePwdCode['verification'] = $code;
$forgePwdCode['time'] = time();
$user->forgePwdCode = json_encode($forgePwdCode);

$mailer = Mailer::getInstance();
$mailer->toQueue(false);
$mail = new Mail();
$mail->to = $user->email;
$mail->subject = '[' . SITE_NAME . '] 新账户注册邮箱校验';
$mail->content = Option::get('custom_mail_verification_content');
$params = [
'code' => $code,
'nickname' => $user->nickname,
'email' => $user->email,
'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down),
'transfer' => Utils::flowAutoShow($user->transfer),
'expireTime' => date('Y-m-d H:i:s', $user->expireTime),
'REGISTER_URL' => base64_encode($user->uid . "\t" . $forgePwdCode['verification'] . "\t" . $forgePwdCode['time'])
];
$mail->content = Utils::placeholderReplace($mail->content, $params);
$mailer->send($mail);
$user->save();
}
return array('error'=>0, 'message'=> '重新发送邮件成功。');
}

/**
* 校验
*
Expand Down Expand Up @@ -303,7 +340,7 @@ public function forgePwd()
}

if($user->enable == 0) {
$verify_code = json_decode($user->forgePwdCode, true)['code'];
$verify_code = json_decode($user->forgePwdCode, true)['verification'];
if($verify_code!=null) {
$result['message'] = '您的账户还未进行邮箱校验,请校验完毕后再试!';
return $result;
Expand Down
9 changes: 8 additions & 1 deletion Library/Controller/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ public function invite()
*/
public function info()
{
Template::putContext('user', User::getCurrent());
$user = User::getUserByUserId(User::getCurrent()->uid);
$json = json_decode($user->forgePwdCode, true);
$flag = true;
if(!$json || $json['verification']==null) {
$flag= false;
}
Template::putContext('is_verification', $flag);
Template::putContext('user', $user);
Template::setView("panel/info");
}

Expand Down
29 changes: 28 additions & 1 deletion Template/Default/panel/info.htm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1 class="title">用户中心</h1>
<div class="panel-body">
<div class="form-group">
<p>用户名:{$user->nickname}</p>
<p>邮箱:{$user->email}</p>
<p>邮箱:{$user->email}&nbsp;<if condition="$is_verification">&nbsp;&nbsp;您还没有校验邮箱地址!(<a href="javascript:;" id="resend_verification">重新发送校验码</a><else>(该邮箱地址已校验)</if></p>
<p>套餐:<span class="label label-info">{$user->getPlan()}</span>
<if condition="$user->plan == 'A'">
&nbsp;&nbsp;您为免费体验账户,流量将不会每月重置,升级到会员账户即可提升流量限额。
Expand Down Expand Up @@ -76,5 +76,32 @@ <h1 class="title">用户中心</h1>
});
}
});
$("#resend_verification").on('click', function(){
var but = $(this);
but.attr("disabled", "disabled").html("60秒才能发送一次");
$.ajax({
url: "/auth/resend.json",
type: "POST",
data: {"auth": 'y'},
dataType: "json",
success: function(result) {
if(result.code != 200) {
showToastr(result.message, 0, '系统错误');
return;
}
if(result.data.error == 0) {
showToastr(result.data.message, 0);
setTimeout('but.removeAttr("disabled").html("重新发送校验码");', 55000);
} else {
showToastr('发送邮件失败', 0);
}
},
error: function(Xhr) {
showToastr('请求服务器失败', 0);
$(".main-content").fadeTo('slow', 1);
}
});

});
</script>
<import template="/panel/_footer" />

0 comments on commit e0100d0

Please sign in to comment.