mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 17:26:38 +08:00
feat: auto login when register successfully
This commit is contained in:
parent
d7e815d2bb
commit
df2fc9d77c
@ -80,14 +80,6 @@ func (h *UserHandler) Register(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 默认订阅所有角色
|
|
||||||
var chatRoles []model.ChatRole
|
|
||||||
h.db.Find(&chatRoles)
|
|
||||||
var roleKeys = make([]string, 0)
|
|
||||||
for _, r := range chatRoles {
|
|
||||||
roleKeys = append(roleKeys, r.Key)
|
|
||||||
}
|
|
||||||
|
|
||||||
salt := utils.RandString(8)
|
salt := utils.RandString(8)
|
||||||
user := model.User{
|
user := model.User{
|
||||||
Password: utils.GenPassword(data.Password, salt),
|
Password: utils.GenPassword(data.Password, salt),
|
||||||
@ -95,7 +87,7 @@ func (h *UserHandler) Register(c *gin.Context) {
|
|||||||
Salt: salt,
|
Salt: salt,
|
||||||
Status: true,
|
Status: true,
|
||||||
Mobile: data.Mobile,
|
Mobile: data.Mobile,
|
||||||
ChatRoles: utils.JsonEncode(roleKeys),
|
ChatRoles: utils.JsonEncode([]string{"gpt"}), // 默认只订阅通用助手角色
|
||||||
ChatConfig: utils.JsonEncode(types.UserChatConfig{
|
ChatConfig: utils.JsonEncode(types.UserChatConfig{
|
||||||
ApiKeys: map[types.Platform]string{
|
ApiKeys: map[types.Platform]string{
|
||||||
types.OpenAI: "",
|
types.OpenAI: "",
|
||||||
@ -116,7 +108,24 @@ func (h *UserHandler) Register(c *gin.Context) {
|
|||||||
if h.App.SysConfig.EnabledMsg {
|
if h.App.SysConfig.EnabledMsg {
|
||||||
_ = h.leveldb.Delete(key) // 注册成功,删除短信验证码
|
_ = h.leveldb.Delete(key) // 注册成功,删除短信验证码
|
||||||
}
|
}
|
||||||
resp.SUCCESS(c, user)
|
|
||||||
|
// 自动登录创建 token
|
||||||
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||||
|
"user_id": user.Id,
|
||||||
|
"expired": time.Now().Add(time.Second * time.Duration(h.App.Config.Session.MaxAge)).Unix(),
|
||||||
|
})
|
||||||
|
tokenString, err := token.SignedString([]byte(h.App.Config.Session.SecretKey))
|
||||||
|
if err != nil {
|
||||||
|
resp.ERROR(c, "Failed to generate token, "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 保存到 redis
|
||||||
|
key = fmt.Sprintf("users/%d", user.Id)
|
||||||
|
if _, err := h.redis.Set(c, key, tokenString, 0).Result(); err != nil {
|
||||||
|
resp.ERROR(c, "error with save token: "+err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp.SUCCESS(c, tokenString)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login 用户登录
|
// Login 用户登录
|
||||||
|
@ -41,10 +41,13 @@
|
|||||||
.page-images-wall .inner .waterfall .list-item .prompt {
|
.page-images-wall .inner .waterfall .list-item .prompt {
|
||||||
display: none;
|
display: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
width: 180px;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
padding: 10px 10px 20px 10px;
|
padding: 10px 10px 20px 10px;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
|
border-top-right-radius: 10px;
|
||||||
background-color: rgba(10,10,10,0.7);
|
background-color: rgba(10,10,10,0.7);
|
||||||
}
|
}
|
||||||
.page-images-wall .inner .waterfall .list-item .prompt .el-icon {
|
.page-images-wall .inner .waterfall .list-item .prompt .el-icon {
|
||||||
|
@ -60,10 +60,13 @@
|
|||||||
.prompt {
|
.prompt {
|
||||||
display none
|
display none
|
||||||
position absolute
|
position absolute
|
||||||
|
width 180px
|
||||||
bottom 0
|
bottom 0
|
||||||
|
left 0
|
||||||
color #ffffff
|
color #ffffff
|
||||||
padding 10px 10px 20px 10px
|
padding 10px 10px 20px 10px
|
||||||
line-height 1.2
|
line-height 1.2
|
||||||
|
border-top-right-radius 10px
|
||||||
background-color rgba(10, 10, 10, 0.7)
|
background-color rgba(10, 10, 10, 0.7)
|
||||||
|
|
||||||
.el-icon {
|
.el-icon {
|
||||||
|
@ -88,7 +88,7 @@ const capabilities = ref([
|
|||||||
value: ""
|
value: ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: "国产大语言模型支持,GLM2 模型接入中",
|
text: "国产大语言模型支持,百度文心,科大讯飞,ChatGLM...",
|
||||||
value: ""
|
value: ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -283,6 +283,7 @@
|
|||||||
</ItemList>
|
</ItemList>
|
||||||
<el-empty :image-size="100" v-else/>
|
<el-empty :image-size="100" v-else/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>创作记录</h2>
|
<h2>创作记录</h2>
|
||||||
<div class="finish-job-list">
|
<div class="finish-job-list">
|
||||||
<ItemList :items="finishedJobs" v-if="finishedJobs.length > 0">
|
<ItemList :items="finishedJobs" v-if="finishedJobs.length > 0">
|
||||||
@ -356,6 +357,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</ItemList>
|
</ItemList>
|
||||||
|
|
||||||
|
<el-empty :image-size="100" v-else/>
|
||||||
</div> <!-- end finish job list-->
|
</div> <!-- end finish job list-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -372,6 +372,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</ItemList>
|
</ItemList>
|
||||||
|
<el-empty :image-size="100" v-else/>
|
||||||
</div> <!-- end finish job list-->
|
</div> <!-- end finish job list-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -619,14 +620,14 @@ onMounted(() => {
|
|||||||
checkSession().then(user => {
|
checkSession().then(user => {
|
||||||
imgCalls.value = user['img_calls']
|
imgCalls.value = user['img_calls']
|
||||||
// 获取运行中的任务
|
// 获取运行中的任务
|
||||||
httpGet("/api/sd/jobs?status=0").then(res => {
|
httpGet(`/api/sd/jobs?status=0&user_id=${user['id']}`).then(res => {
|
||||||
runningJobs.value = res.data
|
runningJobs.value = res.data
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
ElMessage.error("获取任务失败:" + e.message)
|
ElMessage.error("获取任务失败:" + e.message)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 获取运行中的任务
|
// 获取运行中的任务
|
||||||
httpGet("/api/sd/jobs?status=1").then(res => {
|
httpGet(`/api/sd/jobs?status=1&user_id=${user['id']}`).then(res => {
|
||||||
finishedJobs.value = res.data
|
finishedJobs.value = res.data
|
||||||
previewImgList.value = []
|
previewImgList.value = []
|
||||||
for (let index in finishedJobs.value) {
|
for (let index in finishedJobs.value) {
|
||||||
|
@ -109,6 +109,7 @@ import SendMsg from "@/components/SendMsg.vue";
|
|||||||
import {validateMobile} from "@/utils/validate";
|
import {validateMobile} from "@/utils/validate";
|
||||||
import {isMobile} from "@/utils/libs";
|
import {isMobile} from "@/utils/libs";
|
||||||
import SendMsgMobile from "@/components/SendMsg.vue";
|
import SendMsgMobile from "@/components/SendMsg.vue";
|
||||||
|
import {setUserToken} from "@/store/session";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const title = ref('ChatGPT-PLUS 用户注册');
|
const title = ref('ChatGPT-PLUS 用户注册');
|
||||||
@ -144,8 +145,13 @@ const register = function () {
|
|||||||
return ElMessage.error('请输入短信验证码');
|
return ElMessage.error('请输入短信验证码');
|
||||||
}
|
}
|
||||||
formData.value.code = parseInt(formData.value.code)
|
formData.value.code = parseInt(formData.value.code)
|
||||||
httpPost('/api/user/register', formData.value).then(() => {
|
httpPost('/api/user/register', formData.value).then((res) => {
|
||||||
ElMessage.success({"message": "注册成功,即将跳转到登录页...", onClose: () => router.push("/login")})
|
setUserToken(res.data)
|
||||||
|
ElMessage.success({
|
||||||
|
"message": "注册成功,即将跳转到对话主界面...",
|
||||||
|
onClose: () => router.push("/chat"),
|
||||||
|
duration: 1000
|
||||||
|
})
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
ElMessage.error('注册失败,' + e.message)
|
ElMessage.error('注册失败,' + e.message)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user