65 Star 396 Fork 128

admpub/nging

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
profile.go 4.25 KB
一键复制 编辑 原始数据 按行查看 历史
admpub 提交于 2020-02-21 10:57 . 表名称统一增加nging前缀
/*
Nging is a toolbox for webmasters
Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package user
import (
"strings"
"github.com/webx-top/com"
"github.com/webx-top/echo"
"github.com/admpub/nging/application/handler"
"github.com/admpub/nging/application/handler/term"
"github.com/admpub/nging/application/library/common"
"github.com/admpub/nging/application/library/filemanager"
"github.com/admpub/nging/application/model"
)
func Edit(ctx echo.Context) error {
var err error
user := handler.User(ctx)
if user == nil {
return ctx.E(`登录信息获取失败,请重新登录`)
}
m := model.NewUser(ctx)
err = m.Get(nil, `id`, user.Id)
if err != nil {
return err
}
needCheckU2F := m.NeedCheckU2F(user.Id)
if ctx.IsPost() {
email := strings.TrimSpace(ctx.Form(`email`))
mobile := strings.TrimSpace(ctx.Form(`mobile`))
modifyPass := ctx.Form(`modifyPass`) == `1`
//新密码
newPass := strings.TrimSpace(ctx.Form(`newPass`))
confirmPass := strings.TrimSpace(ctx.Form(`confirmPass`))
//旧密码
passwd := strings.TrimSpace(ctx.Form(`pass`))
if modifyPass {
common.DecryptedByRandomSecret(ctx, `modifyProfile`, &passwd, &newPass, &confirmPass)
} else {
common.DecryptedByRandomSecret(ctx, `modifyProfile`, &passwd)
}
gender := strings.TrimSpace(ctx.Form(`gender`))
if len(email) == 0 {
err = ctx.E(`Email不能为空`)
} else if modifyPass && len(newPass) < 8 {
err = ctx.E(`新密码不能少于8个字符`)
} else if modifyPass && newPass != confirmPass {
err = ctx.E(`新密码与确认新密码不一致`)
} else if !ctx.Validate(`email`, email, `email`).Ok() {
err = ctx.E(`Email地址"%s"格式不正确`, email)
} else if len(mobile) > 0 && !ctx.Validate(`mobile`, mobile, `mobile`).Ok() {
err = ctx.E(`手机号"%s"格式不正确`, mobile)
} else if m.NgingUser.Password != com.MakePassword(passwd, m.NgingUser.Salt) {
err = ctx.E(`旧密码输入不正确`)
} else if needCheckU2F {
//两步验证码
err = GAuthVerify(ctx, `u2fCode`)
}
if err == nil && !ctx.Validate(`email`, email, `email`).Ok() {
err = ctx.E(`Email地址格式不正确`)
}
if err == nil {
set := map[string]interface{}{
`email`: email,
`mobile`: mobile,
`avatar`: ctx.Form(`avatar`),
`gender`: gender,
}
if modifyPass {
set[`password`] = com.MakePassword(newPass, m.NgingUser.Salt)
}
err = m.SetFields(nil, set, `id`, user.Id)
}
if err == nil {
handler.SendOk(ctx, ctx.T(`修改成功`))
m.Get(nil, `id`, user.Id)
m.SetSession()
common.DeleteRandomSecret(ctx, `modifyProfile`)
return ctx.Redirect(handler.URLFor(`/user/edit`))
}
}
ctx.Set(`needCheckU2F`, needCheckU2F)
common.SetRandomSecret(ctx, `modifyProfile`, `passwordSecrect`)
return ctx.Render(`user/edit`, handler.Err(ctx, err))
}
func AutoCompletePath(ctx echo.Context) error {
sshAccountID := ctx.Formx(`sshAccountId`).Uint()
if sshAccountID > 0 {
check, _ := ctx.Funcs()[`CheckPerm`].(func(string) error)
data := ctx.Data()
if check == nil {
data.SetData([]string{})
return ctx.JSON(data)
}
if err := check(`manager/command_add`); err != nil {
return err
}
if err := check(`manager/command_edit`); err != nil {
return err
}
return term.SftpSearch(ctx, sshAccountID)
}
data := ctx.Data()
prefix := ctx.Form(`query`)
size := ctx.Formx(`size`, `10`).Int()
var paths []string
switch ctx.Form(`type`) {
case `dir`:
paths = filemanager.SearchDir(prefix, size)
case `file`:
paths = filemanager.SearchFile(prefix, size)
default:
paths = filemanager.Search(prefix, size)
}
data.SetData(paths)
return ctx.JSON(data)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/admpub/nging.git
git@gitee.com:admpub/nging.git
admpub
nging
nging
v2.2.1

搜索帮助