增加文件流返回前的判断,日记文本状态bug,登录提示保存密码(尽力了Vuetify官方都无能为力)
This commit is contained in:
parent
293318e25f
commit
5d3d26b907
|
@ -1,6 +1,7 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"blog/internal/model/AjaxResult"
|
||||
"blog/internal/service"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -19,11 +20,14 @@ type FileController struct {
|
|||
func (ctrl *FileController) ViewFile() {
|
||||
id := ctrl.Ctx.Params().Get("id")
|
||||
file, err := service.FileService.GetFile(id)
|
||||
if err != nil {
|
||||
if err != nil || file.Id == "" {
|
||||
ctrl.Ctx.JSON(AjaxResult.Error("文件不存在"))
|
||||
return
|
||||
}
|
||||
ctrl.Ctx.Header("Content-Disposition", "attachment;filename="+url.QueryEscape(file.FileName))
|
||||
if file.FileSize != 0 {
|
||||
ctrl.Ctx.Header("Content-Length", strconv.FormatInt(file.FileSize, 10))
|
||||
}
|
||||
ctrl.Ctx.Write(file.Data)
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ func (ctrl *DiaryController) PostSubmit() {
|
|||
database.WGorm().Transaction(func(tx *gorm.DB) error {
|
||||
now := time.Now().UnixMilli()
|
||||
diary := admin.AdminDiary{Id: diaryId, PublishTime: now, Del: 0, CreateTime: now, CreateBy: userId}
|
||||
ctn := vo.CommonContent{Id: uuid.NewString(), RelId: diaryId, Content: content}
|
||||
ctn := vo.CommonContent{Id: uuid.NewString(), RelId: diaryId, Content: content, State: consts.CONTENT_STATE_PUBLISH}
|
||||
err = tx.Table("common_contents").Create(ctn).Error
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -57,7 +57,8 @@ func (ctrl *DiaryController) PostSubmit() {
|
|||
for i, file := range files {
|
||||
defer file.Close()
|
||||
header := headers[i]
|
||||
var bytes []byte = make([]byte, header.Size)
|
||||
fileSize := header.Size
|
||||
var bytes []byte = make([]byte, fileSize)
|
||||
_, err = file.Read(bytes)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -65,7 +66,7 @@ func (ctrl *DiaryController) PostSubmit() {
|
|||
fileName := header.Filename
|
||||
fileId := uuid.NewString()
|
||||
fileIds = append(fileIds, fileId)
|
||||
sysFile := admin.SysFile{Id: fileId, FileName: fileName, Data: bytes, Sort: i, Del: 0, CreateBy: userId, CreateTime: now}
|
||||
sysFile := admin.SysFile{Id: fileId, FileName: fileName, FileSize: fileSize, Data: bytes, Sort: i, Del: 0, CreateBy: userId, CreateTime: now}
|
||||
err = tx.Table("common_files").Create(&sysFile).Error
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -60,16 +60,20 @@ func (ctrl *LoginController) GetRefreshcaptcha() {
|
|||
func (ctrl *LoginController) Post() {
|
||||
var loginUser admin.SysUserLogin
|
||||
if err := ctrl.Ctx.ReadBody(&loginUser); err != nil {
|
||||
result := AjaxResult.Error("参数错误")
|
||||
ctrl.Ctx.JSON(result)
|
||||
// result := AjaxResult.Error("参数错误")
|
||||
// ctrl.Ctx.JSON(result)
|
||||
ctrl.Ctx.Redirect("/admin")
|
||||
return
|
||||
}
|
||||
session := sessions.Get(ctrl.Ctx)
|
||||
captcha := loginUser.Captcha
|
||||
sessionCaptcha := session.GetString("captcha")
|
||||
if !strings.EqualFold(captcha, sessionCaptcha) {
|
||||
result := AjaxResult.Error("验证码错误")
|
||||
ctrl.Ctx.JSON(result)
|
||||
// result := AjaxResult.Error("验证码错误")
|
||||
// ctrl.Ctx.JSON(result)
|
||||
ctrl.Ctx.ViewData("user", loginUser)
|
||||
ctrl.Ctx.ViewData("errorMsg", "验证码错误")
|
||||
ctrl.Ctx.View("/admin/login")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -77,12 +81,22 @@ func (ctrl *LoginController) Post() {
|
|||
result := database.GormTemplate.Where("username = ?", loginUser.Username).First(&user)
|
||||
rowsAffected := result.RowsAffected
|
||||
if rowsAffected > 1 {
|
||||
ctrl.Ctx.JSON(AjaxResult.Error("数据异常,后台错误!"))
|
||||
// ctrl.Ctx.JSON(AjaxResult.Error("数据异常,后台错误!"))
|
||||
ctrl.Ctx.Redirect("/admin")
|
||||
return
|
||||
}
|
||||
if rowsAffected == 0 {
|
||||
ctrl.Ctx.ViewData("user", loginUser)
|
||||
ctrl.Ctx.ViewData("errorMsg", "账号不存在")
|
||||
ctrl.Ctx.View("/admin/login")
|
||||
return
|
||||
}
|
||||
err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(loginUser.Password))
|
||||
if err != nil {
|
||||
ctrl.Ctx.JSON(AjaxResult.Error("密码错误!"))
|
||||
// ctrl.Ctx.JSON(AjaxResult.Error("密码错误!"))
|
||||
ctrl.Ctx.ViewData("user", loginUser)
|
||||
ctrl.Ctx.ViewData("errorMsg", "密码错误")
|
||||
ctrl.Ctx.View("/admin/login")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -95,5 +109,6 @@ func (ctrl *LoginController) Post() {
|
|||
|
||||
xFrowardedFor := ctrl.Ctx.GetHeader("X-Forwarded-For")
|
||||
log.Println("用户:", user.Username, "登录,IP为:", xFrowardedFor)
|
||||
ctrl.Ctx.JSON(AjaxResult.Ok("login"))
|
||||
// ctrl.Ctx.JSON(AjaxResult.Ok("login"))
|
||||
ctrl.Ctx.Redirect("/admin")
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ func (*articleService) CreateArticle(articel *admin.AdminArticle) (string, error
|
|||
err := database.WGorm().Transaction(func(tx *gorm.DB) error {
|
||||
contentId := uuid.NewString()
|
||||
content := articel.Content
|
||||
commonContent := vo.CommonContent{Id: contentId, RelId: articleId, Content: content, State: "down"}
|
||||
commonContent := vo.CommonContent{Id: contentId, RelId: articleId, Content: content, State: consts.CONTENT_STATE_DOWN}
|
||||
err := tx.Table("common_contents").Create(commonContent).Error
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -102,8 +102,8 @@
|
|||
axios.post('/admin/diary/submit', formData, {headers: {"Content-Type": "multipart/form-data"}}).then(res => {
|
||||
let data = res.data
|
||||
console.log(data)
|
||||
location.href = '/diary'
|
||||
this.sending = false
|
||||
location.href = '/diary'
|
||||
}).catch(err => {
|
||||
ths.error = err
|
||||
console.error(err)
|
||||
|
|
|
@ -46,13 +46,16 @@
|
|||
<v-alert color="error" type="error" color="red lighten-2" v-if="errorMsg">
|
||||
{{errorMsg}}
|
||||
</v-alert>
|
||||
<v-form ref="form" v-model="valid" lazy-validation>
|
||||
<v-form ref="form" v-model="valid" lazy-validation action="/admin/login" method="post">
|
||||
<v-text-field
|
||||
v-model="username"
|
||||
:rules="requiredRules"
|
||||
label="账号"
|
||||
required
|
||||
name="username"
|
||||
@keyup.enter="login"
|
||||
autocomplete="iris-username"
|
||||
id="iris-username"
|
||||
></v-text-field>
|
||||
<v-text-field
|
||||
v-model="password"
|
||||
|
@ -60,15 +63,20 @@
|
|||
label="密码"
|
||||
required
|
||||
type="password"
|
||||
name="password"
|
||||
@keyup.enter="login"
|
||||
></v-text-field>
|
||||
autocomplete="iris-password"
|
||||
id="iris-password">
|
||||
</v-text-field>
|
||||
<v-text-field
|
||||
v-model="captcha"
|
||||
:rules="requiredRules"
|
||||
label="验证码"
|
||||
required
|
||||
name="captcha"
|
||||
@keyup.enter="login"
|
||||
></v-text-field>
|
||||
id="iris-captcha">
|
||||
</v-text-field>
|
||||
<img :src="captchaBase64" alt='' @click="refreshCaptcha"/>
|
||||
|
||||
<div><v-btn class="mr-4" @click="login">登录</v-btn></div>
|
||||
|
@ -85,7 +93,7 @@
|
|||
template: '#app-template',
|
||||
data: {
|
||||
captchaBase64: '#{.captchaBase64 }',
|
||||
errorMsg: null,
|
||||
errorMsg: "#{.errorMsg}",
|
||||
valid: true,
|
||||
requiredRules: [
|
||||
v => !!v || '不能为空',
|
||||
|
@ -97,6 +105,7 @@
|
|||
},
|
||||
methods: {
|
||||
refreshCaptcha() {
|
||||
console.log("获取验证码");
|
||||
axios.get('/admin/login/refreshcaptcha')
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
|
@ -110,32 +119,47 @@
|
|||
login() {
|
||||
let validate = this.$refs.form.validate()
|
||||
if (validate) {
|
||||
axios.post('/admin/login', {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
captcha: this.captcha,
|
||||
})
|
||||
.then((response) => {
|
||||
// console.log(response);
|
||||
let data = response.data
|
||||
return data
|
||||
}).
|
||||
then((data) => {
|
||||
console.log(data)
|
||||
if (data.code !== 200) {
|
||||
this.errorMsg = data.msg
|
||||
this.refreshCaptcha()
|
||||
return
|
||||
}
|
||||
this.errorMsg = null
|
||||
location.href = "/admin"
|
||||
// console.log(this.$refs.form);
|
||||
localStorage.setItem("username", this.username)
|
||||
localStorage.setItem("password", this.password)
|
||||
this.$refs.form.$el.submit()
|
||||
// axios.post('/admin/login', {
|
||||
// username: this.username,
|
||||
// password: this.password,
|
||||
// captcha: this.captcha,
|
||||
// })
|
||||
// .then((response) => {
|
||||
// // console.log(response);
|
||||
// let data = response.data
|
||||
// return data
|
||||
// }).
|
||||
// then((data) => {
|
||||
// console.log(data)
|
||||
// if (data.code !== 200) {
|
||||
// this.errorMsg = data.msg
|
||||
// this.refreshCaptcha()
|
||||
// return
|
||||
// }
|
||||
// this.errorMsg = null
|
||||
// location.href = "/admin"
|
||||
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// console.log(error);
|
||||
// });
|
||||
}
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
// console.log(this.captchaBase64);
|
||||
if (!this.captchaBase64) {
|
||||
this.refreshCaptcha()
|
||||
}
|
||||
|
||||
if (!this.username) {
|
||||
this.username = localStorage.getItem("username")
|
||||
this.password = localStorage.getItem("password")
|
||||
}
|
||||
|
||||
},
|
||||
vuetify: new Vuetify(),
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
<v-row>
|
||||
<template v-if="item.images.length === 1">
|
||||
<v-col v-for="id in item.images" :key="id"
|
||||
class="d-flex child-flex" cols="6">
|
||||
class="d-flex child-flex" cols="12">
|
||||
<v-img :src="`/file/${id}`" aspect-ratio="1"
|
||||
class="grey lighten-2">
|
||||
<template v-slot:placeholder>
|
||||
|
|
Loading…
Reference in New Issue