Skip to content

Commit

Permalink
1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tavenli committed May 30, 2017
1 parent 56124ec commit 7a76050
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/debug
/lastupdate.tmp
/app.log

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 "在这里输入图片标题")

Expand Down
38 changes: 38 additions & 0 deletions controllers/UCenterCtrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package controllers

import (
"port-forward/controllers/base"
"port-forward/models"
"port-forward/services"
"port-forward/utils"
"runtime"
"time"
Expand Down Expand Up @@ -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()

}
2 changes: 1 addition & 1 deletion models/LoginUser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package models

type LoginUser struct {
UserId int64
UserId int
UserName string
}
14 changes: 14 additions & 0 deletions routers/commentsRouter_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})

}
15 changes: 15 additions & 0 deletions services/SysDataService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions views/ucenter/apiDoc.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

<div style="margin: auto;width: 900px;height: 500px;">

<blockquote class="layui-elem-quote">当前API的AUTH鉴权密钥为:{{config "String" "api.auth" "请在data.conf中配置api.auth属性"}}</blockquote>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
<legend>开启端口转发 接口</legend>
Expand All @@ -22,7 +23,7 @@
<div class="layui-form-item">
<label class="layui-form-label">请求示例</label>
<div class="layui-input-block">
<input type="text" value="/api/v1/OpenForward?auth=xxxxxxxxxx&fromAddr=:8010&toAddr=192.168.1.100:3306" disabled="disabled" class="layui-input">
<input type="text" value="/api/v1/OpenForward?auth={{config "String" "api.auth" "xxxx"}}&fromAddr=:8010&toAddr=192.168.1.100:3306" disabled="disabled" class="layui-input">
</div>
</div>
<div class="layui-form-item">
Expand Down Expand Up @@ -86,7 +87,7 @@
<div class="layui-form-item">
<label class="layui-form-label">请求示例</label>
<div class="layui-input-block">
<input type="text" value="/api/v1/CloseForward?auth=xxxxxxxxxx&fromAddr=:8010&toAddr=192.168.1.100:3306" disabled="disabled" class="layui-input">
<input type="text" value="/api/v1/CloseForward?auth={{config "String" "api.auth" "xxxx"}}&fromAddr=:8010&toAddr=192.168.1.100:3306" disabled="disabled" class="layui-input">
</div>
</div>
<div class="layui-form-item">
Expand Down
64 changes: 64 additions & 0 deletions views/ucenter/changePwd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<div style="margin: auto;width: 900px;height: 500px;">

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
<legend>修改当前用户的登录密码</legend>
</fieldset>

<form id="form1" class="layui-form layui-form-pane" action="/u/doChangePwd" method="POST">
<div class="layui-form-item">
<label class="layui-form-label">新密码</label>
<div class="layui-input-block">
<input type="password" name="passWord" lay-verify="required" placeholder="请输入新的密码" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">确认密码</label>
<div class="layui-input-block">
<input type="password" name="passWord2" lay-verify="required" placeholder="请再次输入新的密码" autocomplete="off" class="layui-input">
</div>
</div>

<div class="layui-form-item">
<div class="layui-input-block">
<button class="layui-btn" lay-submit="" lay-filter="pwd">修改密码</button>
</div>
</div>

</form>

</div>

<script type="text/javascript">
$(document).ready(function () {

layui.use(["form", "element"], function () {
var form = layui.form();

form.on('submit(pwd)', function(data){

submitForm();
loadFrameContent('/u/changePwd');
return false;
});

});

});

function submitForm() {

var postData = $("#form1").serializeArray();
$.post($("#form1").attr("action"), postData, function (json) {
//var data = $.parseJSON(json);
if (json.Code == 0) {
//成功
layer.alert("修改成功");

} else {
//
layer.alert("失败了:" + json.Msg, { icon: 2 });
}
}, "json");
}

</script>
6 changes: 5 additions & 1 deletion views/ucenter/forwardList.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@

</div>
<div class="layui-tab-item">
说明文档请访问:<a href="https://github.com/tavenli/port-forward" target="_blank">https://github.com/tavenli/port-forward</a>
<pre class="layui-code">
说明文档请访问:<a href="https://github.com/tavenli/port-forward" target="_blank">https://github.com/tavenli/port-forward</a>

欢迎大家就使用问题或个性化需求在QQ群中讨论,QQ群号:99134862
</pre>
</div>
</div>
</div>
Expand Down
9 changes: 8 additions & 1 deletion views/ucenter/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@
</dl>
</li>

<li class="layui-nav-item"><a href="javascript:void(0);" onclick="layer.alert('由 Taven.Li 奉献代码');">关于</a></li>
<li class="layui-nav-item">
<a href="javascript:void(0);">其它</a>
<dl class="layui-nav-child">
<dd><a href="javascript:void(0);" onclick="loadFrameContent('/u/changePwd');">修改登录密码</a></dd>
<dd><a href="/logout">退出登录</a></dd>
<dd><a href="javascript:void(0);" onclick="layer.alert('由 Taven.Li 奉献代码');">关于作者</a></dd>
</dl>
</li>
</ul>

0 comments on commit 7a76050

Please sign in to comment.