feat: allow user to login with username and mobile no

This commit is contained in:
RockYang 2023-07-27 15:37:50 +08:00
parent 4faee3e48e
commit a18188876c
6 changed files with 15 additions and 6 deletions

View File

@ -143,7 +143,7 @@ func (h *UserHandler) Login(c *gin.Context) {
return
}
var user model.User
res := h.db.Where("username = ?", data.Username).First(&user)
res := h.db.Where("username = ? OR mobile = ?", data.Username, data.Username).First(&user)
if res.Error != nil {
resp.ERROR(c, "用户名不存在")
return

View File

@ -35,9 +35,12 @@ func (f FuncHeadlines) Invoke(...interface{}) (string, error) {
SetHeader("AppId", f.config.AppId).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", f.config.Token)).
SetSuccessResult(&res).Get(url)
if err != nil || r.IsErrorState() {
if err != nil {
return "", err
}
if r.IsErrorState() {
return "", r.Err
}
if res.Code != types.Success {
return "", errors.New(res.Message)

View File

@ -35,9 +35,12 @@ func (f FuncWeiboHot) Invoke(...interface{}) (string, error) {
SetHeader("AppId", f.config.AppId).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", f.config.Token)).
SetSuccessResult(&res).Get(url)
if err != nil || r.IsErrorState() {
if err != nil {
return "", err
}
if r.IsErrorState() {
return "", r.Err
}
if res.Code != types.Success {
return "", errors.New(res.Message)

View File

@ -35,9 +35,12 @@ func (f FuncZaoBao) Invoke(...interface{}) (string, error) {
SetHeader("AppId", f.config.AppId).
SetHeader("Authorization", fmt.Sprintf("Bearer %s", f.config.Token)).
SetSuccessResult(&res).Get(url)
if err != nil || r.IsErrorState() {
if err != nil {
return "", err
}
if r.IsErrorState() {
return "", r.Err
}
if res.Code != types.Success {
return "", errors.New(res.Message)

View File

@ -11,6 +11,7 @@ services:
ports:
- "6789:5678"
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
- ./conf/config.toml:/var/www/app/config.toml
- ./static:/var/www/app/static
@ -22,7 +23,6 @@ services:
ports:
- "8080:8080"
volumes:
- /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime
- ./logs/nginx:/var/log/nginx
- ./conf/nginx/conf.d:/etc/nginx/conf.d
- ./conf/nginx/nginx.conf:/etc/nginx/nginx.conf

View File

@ -9,7 +9,7 @@
<div class="header">{{ title }}</div>
<div class="content">
<div class="block">
<el-input placeholder="手机号/邮箱" size="large" v-model="username" autocomplete="off">
<el-input placeholder="手机号/用户名" size="large" v-model="username" autocomplete="off">
<template #prefix>
<el-icon>
<UserFilled/>