Browse Source

Merge remote-tracking branch 'origin/master'

layui
aarone 6 years ago
parent
commit
7a6930e33c
  1. 4
      conf/app.conf
  2. 9
      controllers/UserController.go
  3. BIN
      data/beeblog.db
  4. 1
      routers/UserRouter.go
  5. 17
      static/css/login.css
  6. 44
      views/login.html
  7. 64
      views/regist.html

4
conf/app.conf

@ -2,7 +2,9 @@ appname = beeblog
httpport = 8082
runmode = dev
sessionon = true
EnableGzip = true
EnableDocs = true
host = aiprose.com
host = aiprose.com

9
controllers/UserController.go

@ -9,6 +9,7 @@ import (
"time"
"strconv"
"encoding/hex"
"fmt"
)
type UserController struct {
@ -28,6 +29,9 @@ func (u *UserController) LoginPage() {
//u.Ctx.WriteString("login page")
u.TplName = "login.html"
}
func (u *UserController) RegistPage() {
u.TplName = "regist.html"
}
func (this *UserController) Login() {
username := this.GetString("username")
@ -55,6 +59,9 @@ func (this *UserController) Login() {
userpwd = hex.EncodeToString(h.Sum(nil))
if userpwd == user.UserPwd {
this.Data["json"] = models.ReurnSuccess("")
this.SetSession("userid", user.Id)
tt := this.GetSession("userid").(int64)
fmt.Println(tt > 0)
} else {
this.Data["json"] = models.ReurnError("用户名或密码错误")
}
@ -99,7 +106,7 @@ func (this *UserController) Regist() {
user = &models.User{UserName: username, UserPwd: userpwd, Salt: salt}
err := service.SaveUser(user)
if err == nil {
this.Data["json"] = user
this.Data["json"] = models.ReurnSuccess("")
} else {
this.Data["json"] = models.ReurnError("注册失败")
}

BIN
data/beeblog.db

Binary file not shown.

1
routers/UserRouter.go

@ -9,4 +9,5 @@ func init() {
beego.Router("/login", &controllers.UserController{}, "get:LoginPage")
beego.Router("/login", &controllers.UserController{}, "post:Login")
beego.Router("/regist", &controllers.UserController{}, "post:Regist")
beego.Router("/regist", &controllers.UserController{}, "get:RegistPage")
}

17
static/css/login.css

@ -10,9 +10,26 @@
.login-root .input-container{
position: fixed;
left: 65%;
top: 33px;
background: url("/static/img/loginbg.png") no-repeat center top;
}
.login-root .input-container .input-root{
width: 370px;
height: 500px;
}
.login-root .input-container .input-root p {
font-size: 21px;
text-align: center;
padding-top: 195px;
}
.login-root .input-container .input-root .inputs-class{
padding: 0 50px;
}
.login-root .input-container .input-root .inputs-class .input-class{
height: 35px;
margin: 18px 0
}
.login-root .input-container .input-root .inputs-class .input-class input{
height: 35px !important;
}

44
views/login.html

@ -9,9 +9,53 @@
<div class="input-container">
<div class="input-root">
<p>登录</p>
<div class="inputs-class">
<div class="input-group input-group-lg input-class">
<span class="input-group-addon" id="sizing-addon1">用户</span>
<input type="text" class="form-control" placeholder="请输入用户名" aria-describedby="sizing-addon1"
id="username">
</div>
<div class="input-group input-group-lg input-class">
<span class="input-group-addon" id="sizing-addon1">密码</span>
<input type="password" class="form-control" placeholder="请输入密码" aria-describedby="sizing-addon1"
id="userpwd">
</div>
<button type="button" class="btn btn-primary btn-lg btn-bordered btn-block" id="loginBtn">登录
</button>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
$(function () {
$("#loginBtn").click(function () {
var username = $("#username").val()
var userpwd = $("#userpwd").val()
if (username.trim().length < 4) {
layer.msg('用户名最低4位', function () {
});
return
}
if (userpwd.trim().length < 6) {
layer.msg('密码最低6位', function () {
});
return
}
$.post('/login', {
username: username,
userpwd: userpwd
},
function (data) {
console.log(data)
if (data.Status == 1) {
layer.msg(data.Msg, {icon: 5});
}else{
layer.msg("登录成功", {icon: 6});
}
}, 'json')
})
})
</script>
</html>

64
views/regist.html

@ -0,0 +1,64 @@
{{template "header"}}
<title>注册 - 个人随笔</title>
<link type="text/css" rel="styleSheet" href="/static/css/login.css"/>
</head>
<body>
<div class="root-container">
{{template "nav" .}}
<div class="login-root">
<div class="input-container">
<div class="input-root">
<p>注册</p>
<div class="inputs-class">
<div class="input-group input-group-lg input-class">
<span class="input-group-addon" id="sizing-addon1">用户</span>
<input type="text" class="form-control" placeholder="请输入用户名" id="username"
aria-describedby="sizing-addon1">
</div>
<div class="input-group input-group-lg input-class">
<span class="input-group-addon" id="sizing-addon1">密码</span>
<input type="password" class="form-control" placeholder="请输入密码" id="userpwd"
aria-describedby="sizing-addon1">
</div>
<button type="button" class="btn btn-primary btn-lg btn-bordered btn-block" id="loginBtn">注册
</button>
</div>
</div>
</div>
</div>
</div>
</body>
<script>
$(function () {
$("#loginBtn").click(function () {
var username = $("#username").val()
var userpwd = $("#userpwd").val()
if (username.trim().length < 4) {
layer.msg('用户名最低4位', function () {
});
return
}
if (userpwd.trim().length < 6) {
layer.msg('密码最低6位', function () {
});
return
}
$.post('/regist', {
username: username,
userpwd: userpwd
},
function (data) {
console.log(data)
if (data.Status == 1) {
layer.msg(data.Msg, {icon: 5});
} else {
layer.msg("注册成功,现在去登陆哦", {icon: 6});
setTimeout(function () {
window.location.href = "/login"
}, 800)
}
}, 'json')
})
})
</script>
</html>
Loading…
Cancel
Save