feat: 注册邀请码模式

This commit is contained in:
kuaifan 2021-12-26 23:38:47 +08:00
parent dd86bb88c6
commit 91f25e9ec3
2 changed files with 54 additions and 11 deletions

View File

@ -31,7 +31,7 @@ class UsersController extends AbstractController
* @apiParam {String} email 邮箱
* @apiParam {String} password 密码
* @apiParam {String} [code] 登录验证码
* @apiParam {String} [key] 登陆验证码key
* @apiParam {String} [invite] 注册邀请码
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
@ -46,24 +46,22 @@ class UsersController extends AbstractController
$setting = Base::setting('system');
if ($setting['reg'] == 'close') {
return Base::retError('未开放注册');
} elseif ($setting['reg'] == 'invite') {
$invite = trim(Request::input('invite'));
if (empty($invite) || $invite != $setting['reg_invite']) {
return Base::retError('请输入正确的邀请码');
}
}
$user = User::reg($email, $password);
} else {
$needCode = !Base::isError(User::needCode($email));
if ($needCode) {
$code = trim(Request::input('code'));
$key = trim(Request::input('key'));
if (empty($code)) {
return Base::retError('请输入验证码', ['code' => 'need']);
}
if (empty($key)) {
if (!Captcha::check($code)) {
return Base::retError('请输入正确的验证码', ['code' => 'need']);
}
} else {
if (!Captcha::check_api($code, $key)) {
return Base::retError('请输入正确的验证码', ['code' => 'need']);
}
if (!Captcha::check($code)) {
return Base::retError('请输入正确的验证码', ['code' => 'need']);
}
}
//
@ -154,6 +152,25 @@ class UsersController extends AbstractController
return Base::retSuccess('请求成功', $captcha);
}
/**
* @api {get} api/users/reg/needinvite 04. 是否需要邀请码
*
* @apiDescription 用于判断注册是否需要邀请码
* @apiVersion 1.0.0
* @apiGroup users
* @apiName reg__needinvite
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function reg__needinvite()
{
return Base::retSuccess('success', [
'need' => Base::settingFind('system', 'reg') == 'invite'
]);
}
/**
* @api {get} api/users/info 05. 获取我的信息
*

View File

@ -19,11 +19,13 @@
<Input v-model="password" prefix="ios-lock-outline" :placeholder="$L('输入您的密码')" type="password" size="large" @on-enter="onLogin" />
<Input v-if="loginType=='reg'" v-model="password2" prefix="ios-lock-outline" :placeholder="$L('输入确认密码')" type="password" size="large" @on-enter="onLogin" />
<Input v-if="loginType=='reg' && regNeedInvite" v-model="invite" class="login-code" :placeholder="$L('请输入注册邀请码')" type="text" size="large" @on-enter="onLogin"><span slot="prepend">&nbsp;{{$L('邀请码')}}&nbsp;</span></Input>
<Input v-if="codeNeed" v-model="code" class="login-code" :placeholder="$L('输入图形验证码')" size="large" @on-enter="onLogin">
<Input v-if="loginType=='login' && codeNeed" v-model="code" class="login-code" :placeholder="$L('输入图形验证码')" size="large" @on-enter="onLogin">
<Icon type="ios-checkmark-circle-outline" class="login-icon" slot="prepend"></Icon>
<div slot="append" class="login-code-end" @click="reCode"><img :src="codeUrl"/></div>
</Input>
<Button type="primary" :loading="loadIng > 0 || loginJump" size="large" long @click="onLogin">{{$L(loginText)}}</Button>
<div v-if="loginType=='reg'" class="login-switch">{{$L('已经有帐号?')}}<a href="javascript:void(0)" @click="loginType='login'">{{$L('登录帐号')}}</a></div>
@ -64,8 +66,11 @@ export default {
password: '',
password2: '',
code: '',
invite: '',
demoAccount: {},
regNeedInvite: false,
}
},
mounted() {
@ -86,6 +91,13 @@ export default {
return text
}
},
watch: {
loginType(val) {
if (val == 'reg') {
this.getNeedInvite();
}
}
},
methods: {
getDemoAccount() {
this.$store.dispatch("call", {
@ -101,6 +113,16 @@ export default {
});
},
getNeedInvite() {
this.$store.dispatch("call", {
url: 'users/reg/needinvite',
}).then(({data}) => {
this.regNeedInvite = !!data.need;
}).catch(() => {
this.regNeedInvite = false;
});
},
forgotPassword() {
$A.modalWarning("请联系管理员!");
},
@ -151,9 +173,13 @@ export default {
email: this.email,
password: this.password,
code: this.code,
invite: this.invite,
},
}).then(({data}) => {
this.loadIng--;
this.password = "";
this.code = "";
this.invite = "";
this.$store.state.method.setStorage("cacheLoginEmail", this.email)
this.$store.dispatch("handleClearCache", data).then(() => {
this.goNext1();