From 7a76050a6079445985044c12bf7ff6ec72fac564 Mon Sep 17 00:00:00 2001 From: TavenLi Date: Tue, 30 May 2017 23:16:09 +0800 Subject: [PATCH] 1.0 --- .gitignore | 4 ++ README.md | 13 ++++++ controllers/UCenterCtrl.go | 38 ++++++++++++++++ models/LoginUser.go | 2 +- routers/commentsRouter_controllers.go | 14 ++++++ services/SysDataService.go | 15 +++++++ views/ucenter/apiDoc.html | 5 ++- views/ucenter/changePwd.html | 64 +++++++++++++++++++++++++++ views/ucenter/forwardList.html | 6 ++- views/ucenter/header.html | 9 +++- 10 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 views/ucenter/changePwd.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e85da64 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/debug +/lastupdate.tmp +/app.log + diff --git a/README.md b/README.md index f25c726..e316194 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,19 @@ Go语言开发的端口转发工具 for port data forward > 支持API接口,方便与其它系统集成 +# 使用交流群 + +> 欢迎大家就使用问题或个性化需求在QQ群中讨论,QQ群号:99134862 + +# 快速安装说明 +1. 下载编译好的程序包,并解压程序包 +2. 在执行程序包目录下找 data/PortForwardDb.sql 的数据库创建文件,创建好数据库 PortForwardDb +3. 修改 conf/data.conf 中的数据库连接串,主要是修改连接MySQL的用户名和密码 +4. 执行 start.sh (Linux)或 start.bat (Win)命令 +5. 打开浏览器,进入控制台,打开 http://127.0.0.1:8000/login +6. 输入用户 admin 密码 123456 进入控制台 + + # 控制台UI ![登录](http://git.oschina.net/tavenli/port-forward/raw/master/screenshot/Login.png "在这里输入图片标题") diff --git a/controllers/UCenterCtrl.go b/controllers/UCenterCtrl.go index 9a6eccf..6a1bbbc 100644 --- a/controllers/UCenterCtrl.go +++ b/controllers/UCenterCtrl.go @@ -2,6 +2,8 @@ package controllers import ( "port-forward/controllers/base" + "port-forward/models" + "port-forward/services" "port-forward/utils" "runtime" "time" @@ -39,3 +41,39 @@ func (c *UCenterCtrl) GetServerTime() { c.ServeJSON() } + +// @router /u/changePwd [get] +func (c *UCenterCtrl) ChangePwd() { + + c.TplName = "ucenter/changePwd.html" +} + +// @router /u/doChangePwd [post] +func (c *UCenterCtrl) DoChangePwd() { + userInfo := c.GetUserInfo() + + passWord := c.GetString("passWord") + passWord2 := c.GetString("passWord2") + + if utils.IsEmpty(passWord) { + c.Data["json"] = models.ResultData{Code: 1, Msg: "密码不能为空"} + c.ServeJSON() + return + } + + if passWord != passWord2 { + c.Data["json"] = models.ResultData{Code: 1, Msg: "两次输入的密码不一致"} + c.ServeJSON() + return + } + + err := services.SysDataS.ChangeUserPwd(userInfo.UserId, passWord) + if err == nil { + c.Data["json"] = models.ResultData{Code: 0, Msg: "密码修改成功"} + } else { + c.Data["json"] = models.ResultData{Code: 1, Msg: err.Error()} + } + + c.ServeJSON() + +} diff --git a/models/LoginUser.go b/models/LoginUser.go index 503c9e2..9248962 100644 --- a/models/LoginUser.go +++ b/models/LoginUser.go @@ -1,6 +1,6 @@ package models type LoginUser struct { - UserId int64 + UserId int UserName string } diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 99106bf..b6b4e74 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -153,4 +153,18 @@ func init() { AllowHTTPMethods: []string{"post"}, Params: nil}) + beego.GlobalControllerRouter["port-forward/controllers:UCenterCtrl"] = append(beego.GlobalControllerRouter["port-forward/controllers:UCenterCtrl"], + beego.ControllerComments{ + Method: "ChangePwd", + Router: `/u/changePwd`, + AllowHTTPMethods: []string{"get"}, + Params: nil}) + + beego.GlobalControllerRouter["port-forward/controllers:UCenterCtrl"] = append(beego.GlobalControllerRouter["port-forward/controllers:UCenterCtrl"], + beego.ControllerComments{ + Method: "DoChangePwd", + Router: `/u/doChangePwd`, + AllowHTTPMethods: []string{"post"}, + Params: nil}) + } diff --git a/services/SysDataService.go b/services/SysDataService.go index c42e225..d953b93 100644 --- a/services/SysDataService.go +++ b/services/SysDataService.go @@ -49,6 +49,21 @@ func (_self *SysDataService) GetSysUserByName(userName string) *models.SysUser { } +func (_self *SysDataService) ChangeUserPwd(id int, password string) error { + pwd := utils.GetMd5(password) + res, err := OrmerS.Raw("update t_sys_user SET passWord = ? where id = ?", + pwd, id).Exec() + if err == nil { + num, _ := res.RowsAffected() + logs.Debug("ChangeUserPwd", num) + + } else { + logs.Error("ChangeUserPwd", err) + + } + return err +} + func (_self *SysDataService) UpdateSysUser(entity *models.SysUser) error { _, err := OrmerS.Update(entity) diff --git a/views/ucenter/apiDoc.html b/views/ucenter/apiDoc.html index b430805..e7882ca 100644 --- a/views/ucenter/apiDoc.html +++ b/views/ucenter/apiDoc.html @@ -1,6 +1,7 @@
+
当前API的AUTH鉴权密钥为:{{config "String" "api.auth" "请在data.conf中配置api.auth属性"}}
开启端口转发 接口 @@ -22,7 +23,7 @@
- +
@@ -86,7 +87,7 @@
- +
diff --git a/views/ucenter/changePwd.html b/views/ucenter/changePwd.html new file mode 100644 index 0000000..64c2c79 --- /dev/null +++ b/views/ucenter/changePwd.html @@ -0,0 +1,64 @@ +
+ +
+ 修改当前用户的登录密码 +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+ +
+ + \ No newline at end of file diff --git a/views/ucenter/forwardList.html b/views/ucenter/forwardList.html index 63c0789..2483f63 100644 --- a/views/ucenter/forwardList.html +++ b/views/ucenter/forwardList.html @@ -46,7 +46,11 @@
- 说明文档请访问:https://github.com/tavenli/port-forward +
+说明文档请访问:https://github.com/tavenli/port-forward
+
+欢迎大家就使用问题或个性化需求在QQ群中讨论,QQ群号:99134862
+            
diff --git a/views/ucenter/header.html b/views/ucenter/header.html index 5a3c77b..d1daa74 100644 --- a/views/ucenter/header.html +++ b/views/ucenter/header.html @@ -10,5 +10,12 @@ -
  • 关于
  • +
  • + 其它 +
    +
    修改登录密码
    +
    退出登录
    +
    关于作者
    +
    +
  • \ No newline at end of file