refactor, fix bug and update i18n(user center), to be continue

pull/680/head
shiqstone 2021-04-19 14:32:55 +08:00
parent 93d377f3b9
commit d9e2b0bc8b
5 changed files with 108 additions and 53 deletions

View File

@ -3,7 +3,7 @@ title = mindoc
home = Home
blog = Blog
project_space = Project Space
person_center = Persona Center
person_center = Personal Center
my_project = My Project
my_blog = My Article
manage = Management
@ -185,6 +185,15 @@ ref_doc_not_exist_or_no_permit = reference document does not exist or has insuff
blog_id_existed = blog id already existed
query_failed = query failed
blog_has_modified = The article has been modified
cur_user_cannot_change_pwd = The current user does not support changing the password
origin_pwd_empty = The origin password cannot be empty
new_pwd_empty = The new password cannot be empty
confirm_pwd_empty = The confirm password cannot be empty
pwd_length = Password must be between 6-18 characters
wrong_origin_pwd = The origin password incorrect
wrong_confirm_pwd = The confirm passwrod incorrect
same_pwd = The new password must different from the origin
pwd_encrypt_failed = Password encryption failed
[blog]
author = Author
@ -420,4 +429,21 @@ no_result = No search result
first = first
last = last
prev = prev
next = next
next =
[uc]
user_center = User Center
base_info = Basic Info
change_pwd = Change Password
username = Username
nickname = Nickname
realname = Real name
email = Email
mobile = Mobile
description = Description
description_tips = Description cannot exceed 500 characters
avatar = Avatar
change_avatar = Change avatar
origin_pwd = Origin password
new_pwd = New password
confirm_pwd = Confirm password

View File

@ -185,6 +185,15 @@ ref_doc_not_exist_or_no_permit = 关联文档不存在或权限不足
blog_id_existed = 文章标识已存在
query_failed = 查询失败
blog_has_modified = 文章已被修改
cur_user_cannot_change_pwd = 当前用户不支持修改密码
origin_pwd_empty = 原密码不能为空
new_pwd_empty = 新密码不能为空
confirm_pwd_empty = 确认密码不能为空
pwd_length = 密码必须在6-18字之间
wrong_origin_pwd = 原始密码不正确
wrong_confirm_pwd = 确认密码不正确
same_pwd = 新密码不能和原始密码相同
pwd_encrypt_failed = 密码加密失败
[blog]
author = 作者
@ -420,4 +429,21 @@ no_result = 暂无相关搜索结果
first = 首页
last = 末页
prev = 上一页
next = 下一页
next = 下一页
[uc]
user_center = 用户中心
base_info = 基本信息
change_pwd = 修改密码
username = 用户名
nickname = 昵称
realname = 真实姓名
email = 邮箱
mobile = 手机号
description = 描述
description_tips = 描述不能超过500字
avatar = 头像
change_avatar = 修改头像
origin_pwd = 原始密码
new_pwd = 新密码
confirm_pwd = 确认密码

View File

@ -9,6 +9,7 @@ import (
"time"
"github.com/astaxie/beego/logs"
"github.com/beego/i18n"
"github.com/mindoc-org/mindoc/conf"
"github.com/mindoc-org/mindoc/graphics"
"github.com/mindoc-org/mindoc/models"
@ -28,7 +29,7 @@ func (c *SettingController) Index() {
description := strings.TrimSpace(c.GetString("description"))
if email == "" {
c.JsonResult(601, "邮箱不能为空")
c.JsonResult(601, i18n.Tr(c.Lang, "message.email_empty"))
}
member := c.Member
member.Email = email
@ -48,34 +49,34 @@ func (c *SettingController) Password() {
if c.Ctx.Input.IsPost() {
if c.Member.AuthMethod == conf.AuthMethodLDAP {
c.JsonResult(6009, "当前用户不支持修改密码")
c.JsonResult(6009, i18n.Tr(c.Lang, "message.cur_user_cannot_change_pwd"))
}
password1 := c.GetString("password1")
password2 := c.GetString("password2")
password3 := c.GetString("password3")
if password1 == "" {
c.JsonResult(6003, "原密码不能为空")
c.JsonResult(6003, i18n.Tr(c.Lang, "message.origin_pwd_empty"))
}
if password2 == "" {
c.JsonResult(6004, "新密码不能为空")
c.JsonResult(6004, i18n.Tr(c.Lang, "message.new_pwd_empty"))
}
if count := strings.Count(password2, ""); count < 6 || count > 18 {
c.JsonResult(6009, "密码必须在6-18字之间")
c.JsonResult(6009, i18n.Tr(c.Lang, "message.pwd_length"))
}
if password2 != password3 {
c.JsonResult(6003, "确认密码不正确")
}
if ok, _ := utils.PasswordVerify(c.Member.Password, password1); !ok {
c.JsonResult(6005, "原始密码不正确")
c.JsonResult(6005, i18n.Tr(c.Lang, "message.wrong_origin_pwd"))
}
if password1 == password2 {
c.JsonResult(6006, "新密码不能和原始密码相同")
c.JsonResult(6006, i18n.Tr(c.Lang, "message.same_pwd"))
}
pwd, err := utils.PasswordHash(password2)
if err != nil {
c.JsonResult(6007, "密码加密失败")
c.JsonResult(6007, i18n.Tr(c.Lang, "message.pwd_encrypt_failed"))
}
c.Member.Password = pwd
if err := c.Member.Update(); err != nil {

View File

@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用户中心 - Powered by MinDoc</title>
<title>{{i18n .Lang "uc.user_center"}} - Powered by MinDoc</title>
<!-- Bootstrap -->
<link href="{{cdncss "/static/bootstrap/css/bootstrap.min.css"}}" rel="stylesheet">
@ -28,44 +28,44 @@
<div class="row">
<div class="page-left">
<ul class="menu">
<li class="active"><a href="{{urlfor "SettingController.Index"}}" class="item"><i class="fa fa-sitemap" aria-hidden="true"></i> 基本信息</a> </li>
<li class="active"><a href="{{urlfor "SettingController.Index"}}" class="item"><i class="fa fa-sitemap" aria-hidden="true"></i> {{i18n .Lang "uc.base_info"}}</a> </li>
{{if ne .Member.AuthMethod "ldap"}}
<li><a href="{{urlfor "SettingController.Password"}}" class="item"><i class="fa fa-user" aria-hidden="true"></i> 修改密码</a> </li>
<li><a href="{{urlfor "SettingController.Password"}}" class="item"><i class="fa fa-user" aria-hidden="true"></i> {{i18n .Lang "uc.change_pwd"}}</a> </li>
{{end}}
</ul>
</div>
<div class="page-right">
<div class="m-box">
<div class="box-head">
<strong class="box-title">基本信息</strong>
<strong class="box-title">{{i18n .Lang "uc.base_info"}}</strong>
</div>
</div>
<div class="box-body" style="padding-right: 200px;">
<div class="form-left">
<form role="form" method="post" id="memberInfoForm">
<div class="form-group">
<label>用户名</label>
<input type="text" class="form-control disabled" value="{{.Member.Account}}" disabled placeholder="用户名">
<label>{{i18n .Lang "uc.username"}}</label>
<input type="text" class="form-control disabled" value="{{.Member.Account}}" disabled placeholder="{{i18n .Lang "uc.username"}}">
</div>
<div class="form-group">
<label>真实姓名</label>
<input type="text" name="real_name" class="form-control" value="{{.Member.RealName}}" placeholder="真实姓名">
<label>{{i18n .Lang "uc.realname"}}</label>
<input type="text" name="real_name" class="form-control" value="{{.Member.RealName}}" placeholder="{{i18n .Lang "uc.realname"}}">
</div>
<div class="form-group">
<label for="user-email">邮箱<strong class="text-danger">*</strong></label>
<input type="email" class="form-control" value="{{.Member.Email}}" id="userEmail" name="email" max="100" placeholder="邮箱">
<label for="user-email">{{i18n .Lang "uc.email"}}<strong class="text-danger">*</strong></label>
<input type="email" class="form-control" value="{{.Member.Email}}" id="userEmail" name="email" max="100" placeholder="{{i18n .Lang "uc.email"}}">
</div>
<div class="form-group">
<label>手机号</label>
<input type="text" class="form-control" id="userPhone" name="phone" maxlength="20" title="手机号码" placeholder="手机号码" value="{{.Member.Phone}}">
<label>{{i18n .Lang "uc.mobile"}}</label>
<input type="text" class="form-control" id="userPhone" name="phone" maxlength="20" title="{{i18n .Lang "uc.mobile"}}" placeholder="{{i18n .Lang "uc.mobile"}}" value="{{.Member.Phone}}">
</div>
<div class="form-group">
<label class="description">描述</label>
<textarea class="form-control" rows="3" title="描述" name="description" id="description" maxlength="500">{{.Member.Description}}</textarea>
<p style="color: #999;font-size: 12px;">描述不能超过500字</p>
<label class="description">{{i18n .Lang "uc.description"}}</label>
<textarea class="form-control" rows="3" title="{{i18n .Lang "uc.description"}}" name="description" id="description" maxlength="500">{{.Member.Description}}</textarea>
<p style="color: #999;font-size: 12px;">{{i18n .Lang "uc.description_tips"}}</p>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success" data-loading-text="保存中...">保存修改</button>
<button type="submit" class="btn btn-success" data-loading-text="{{i18n .Lang "message.processing"}}">{{i18n .Lang "common.save"}}</button>
<span id="form-error-message" class="error-message"></span>
</div>
</form>
@ -73,7 +73,7 @@
<div class="form-right">
<label>
<a href="javascript:;" data-toggle="modal" data-target="#upload-logo-panel">
<img src="{{cdnimg .Member.Avatar}}" onerror="this.src='{{cdnimg "static/images/middle.gif"}}'" class="img-circle" alt="头像" style="max-width: 120px;max-height: 120px;" id="headimgurl">
<img src="{{cdnimg .Member.Avatar}}" onerror="this.src='{{cdnimg "static/images/middle.gif"}}'" class="img-circle" alt="{{i18n .Lang "uc.avatar"}}" style="max-width: 120px;max-height: 120px;" id="headimgurl">
</a>
</label>
</div>
@ -84,12 +84,12 @@
{{template "widgets/footer.tpl" .}}
</div>
<!-- Start Modal -->
<div class="modal fade" id="upload-logo-panel" tabindex="-1" role="dialog" aria-labelledby="修改头像" aria-hidden="true">
<div class="modal fade" id="upload-logo-panel" tabindex="-1" role="dialog" aria-labelledby="{{i18n .Lang "uc.change_avatar"}})" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">修改头像</h4>
<h4 class="modal-title">{{i18n .Lang "uc.change_avatar"}}</h4>
</div>
<div class="modal-body">
<div class="wraper">
@ -98,7 +98,7 @@
</div>
</div>
<div class="watch-crop-list">
<div class="preview-title">预览</div>
<div class="preview-title">{{i18n .Lang "uc.change_avatar"}}</div>
<ul>
<li>
<div class="img-preview preview-lg"></div>
@ -112,8 +112,8 @@
</div>
<div class="modal-footer">
<span id="error-message"></span>
<div id="filePicker" class="btn">选择</div>
<button type="button" id="saveImage" class="btn btn-success" style="height: 40px;width: 77px;" data-loading-text="上传中...">上传</button>
<div id="filePicker" class="btn">{{i18n .Lang "blog.choose"}}</div>
<button type="button" id="saveImage" class="btn btn-success" style="height: 40px;width: 77px;" data-loading-text="{{i18n .Lang "message.processing"}}">{{i18n .Lang "blog.upload"}}</button>
</div>
</div>
</div>
@ -139,14 +139,14 @@
var email = $.trim($("#userEmail").val());
if(!email){
return showError('邮箱不能为空');
return showError('{{i18n .Lang "message.email_empty"}}');
}
$("button[type='submit']").button('loading');
},
success : function (res) {
$("button[type='submit']").button('reset');
if(res.errcode === 0){
showSuccess("保存成功");
showSuccess("{{i18n .Lang "message.success"}}");
}else{
showError(res.message);
}
@ -173,7 +173,7 @@
uploader.makeThumb( file, function( error, src ) {
$img = '<img src="' + src +'" style="max-width: 360px;max-height: 360px;">';
if ( error ) {
$img.replaceWith('<span>不能预览</span>');
$img.replaceWith('<span>{{i18n .Lang "message.cannot_preview"}}</span>');
return;
}
@ -187,7 +187,7 @@
}, 1, 1 );
}).on("uploadError",function (file,reason) {
console.log(reason);
$("#error-message").text("上传失败:" + reason);
$("#error-message").text("{{i18n .Lang "message.upload_failed"}}:" + reason);
}).on("uploadSuccess",function (file, res) {

View File

@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>用户中心 - Powered by MinDoc</title>
<title>{{i18n .Lang "uc.user_center"}} - Powered by MinDoc</title>
<!-- Bootstrap -->
<link href="{{cdncss "/static/bootstrap/css/bootstrap.min.css"}}" rel="stylesheet">
@ -26,34 +26,36 @@
<div class="row">
<div class="page-left">
<ul class="menu">
<li><a href="{{urlfor "SettingController.Index"}}" class="item"><i class="fa fa-sitemap" aria-hidden="true"></i> 基本信息</a> </li>
<li class="active"><a href="{{urlfor "SettingController.Password"}}" class="item"><i class="fa fa-user" aria-hidden="true"></i> 修改密码</a> </li>
<li><a href="{{urlfor "SettingController.Index"}}" class="item"><i class="fa fa-sitemap" aria-hidden="true"></i> {{i18n .Lang "uc.base_info"}}</a> </li>
<li class="active"><a href="{{urlfor "SettingController.Password"}}" class="item"><i class="fa fa-user" aria-hidden="true"></i> {{i18n .Lang "uc.change_pwd"}}</a> </li>
</ul>
</div>
<div class="page-right">
<div class="m-box">
<div class="box-head">
<strong class="box-title">修改密码</strong>
<strong class="box-title">{{i18n .Lang "uc.change_pwd"}}</strong>
</div>
</div>
<div class="box-body" style="width: 300px;">
<form role="form" method="post" id="securityForm">
<div class="form-group">
<label for="password1">原始密码</label>
<input type="password" name="password1" id="password1" class="form-control disabled" placeholder="原始密码">
<label for="password1">{{i18n .Lang "uc.origin_pwd"}}</label>
<input type="password" name="password1" id="password1" class="form-control disabled" placeholder="{{i18n .Lang "uc.origin_pwd"}}">
</div>
<div class="form-group">
<label for="password2">新密码</label>
<input type="password" class="form-control" name="password2" id="password2" max="50" placeholder="新密码">
<label for="password2">{{i18n .Lang "uc.new_pwd"}}</label>
<input type="password" class="form-control" name="password2" id="password2" max="50" placeholder="{{i18n .Lang "uc.new_pwd"}}">
</div>
<div class="form-group">
<label for="password3">确认密码</label>
<input type="password" class="form-control" id="password3" name="password3" placeholder="确认密码">
<label for="password3">{{i18n .Lang "uc.confirm_pwd"}}</label>
<input type="password" class="form-control" id="password3" name="password3" placeholder="{{i18n .Lang "uc.confirm_pwd"}}">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success" data-loading-text="保存中...">保存修改</button>
<span id="form-error-message" class="error-message"></span>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success" data-loading-text="{{i18n .Lang "message.processing"}}">{{i18n .Lang "message.save"}}</button>
</div>
</form>
</div>
</div>
@ -74,25 +76,25 @@
var newPasswd = $("#password2").val();
var confirmPassword = $("#password3").val();
if(!oldPasswd ){
showError("原始密码不能为空");
showError({{i18n .Lang "message.origin_pwd_empty"}});
return false;
}
if(!newPasswd){
showError("新密码不能为空");
showError({{i18n .Lang "message.new_pwd_empty"}});
return false;
}
if(!confirmPassword){
showError("确认密码不能为空");
showError({{i18n .Lang "message.confirm_pwd_empty"}});
return false;
}
if(confirmPassword !== newPasswd){
showError("确认密码不正确");
showError({{i18n .Lang "message.wrong_confirm_pwd"}});
return false;
}
},
success : function (res) {
if(res.errcode === 0){
showSuccess('保存成功');
showSuccess({{i18n .Lang "message.success"}});
$("#password1").val('');
$("#password2").val('');
$("#password3").val('');