昨日回顾
1 前端登录,注册组件
2 分析写几个接口
-多方式登录接口(写完)
-验证码登录接口
-发送验证码接口
-验证手机号是否存在接口
-短信注册接口
3 补充:
-登录接口密码是否加密
-密码是明文,不加密(不安全)
-把密码加密(md5+base64) (也不安全)
-整个把请求体中内容加密了(比较安全)
今日内容
1 校验手机号是否存在接口
@action(methods=['GET'], detail=False)
def check_mobile(self,request):
mobile=request.query_params.get('mobile',None)
if mobile:
user=User.objects.filter(mobile=mobile).first()
if user:
return APIResponse(exisit=True)
else:
return APIResponse(exisit=False)
2 多方式登录功能前端和注销功能
2.1 Login.vue
<template>
<div class="login">
<div class="box">
<i class="el-icon-close" @click="close_login"></i>
<div class="content">
<div class="nav">
<span :class="{active: login_method === 'is_pwd'}"
@click="change_login_method('is_pwd')">密码登录</span>
<span :class="{active: login_method === 'is_sms'}"
@click="change_login_method('is_sms')">短信登录</span>
</div>
<el-form v-if="login_method === 'is_pwd'">
<el-input
placeholder="用户名/手机号/邮箱"
prefix-icon="el-icon-user"
v-model="username"
clearable>
</el-input>
<el-input
placeholder="密码"
prefix-icon="el-icon-key"
v-model="password"
clearable
show-password>
</el-input>
<el-button type="primary" @click="login_pwd">登录</el-button>
</el-form>
<el-form v-if="login_method === 'is_sms'">
<el-input
placeholder="手机号"
prefix-icon="el-icon-phone-outline"
v-model="mobile"
clearable
@blur="check_mobile">
</el-input>
<el-input
placeholder="验证码"
prefix-icon="el-icon-chat-line-round"
v-model="sms"
clearable>
<template slot="append">
<span class="sms" @click="send_sms">{
{ sms_interval }}</span>
</template>
</el-input>
<el-button type="primary">登录</el-button>
</el-form>
<div class="foot">
<span @click="go_register">立即注册</span>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "Login",
data() {
return {
username: '',
password: '',
mobile: '',
sms: '',
login_method: 'is_pwd',
sms_interval: '获取验证码',
is_send: false,
}
},
methods: {
close_login() {
this.$emit('close')
},
go_register