实现回到头部

This commit is contained in:
Minho 2017-05-16 15:50:12 +08:00
parent fc6ec31b31
commit f89f369c0d
5 changed files with 193 additions and 1 deletions

View File

@ -23,7 +23,6 @@ func main() {
commands.RegisterCommand()
commands.RegisterFunction()
beego.SetStaticPath("uploads", "uploads")
beego.ErrorController(&controllers.ErrorController{})

View File

@ -452,6 +452,48 @@ h6 {
border-top: 1px solid #DDDDDD;
padding-top: 15px;
}
.manual-article .jump-top .view-backtop{
position: fixed;
bottom: -30px;
right: 30px;
font-size: 18px;
line-height: 30px;
text-align: center;
color: #fff;
z-index: 9999;
font-weight: 200;
width: 30px;
height: 30px;
background-color: #999;
border-radius: 4px;
opacity: 0;
filter: alpha(opacity=0);
transition-property: all;
transition-duration: .2s;
transition-timing-function: linear;
transition-delay: 0s;
-moz-transition-property: all;
-moz-transition-duration: .2s;
-moz-transition-timing-function: linear;
-moz-transition-delay: 0s;
-webkit-transition-property: all;
-webkit-transition-duration: .2s;
-webkit-transition-timing-function: linear;
-webkit-transition-delay: 0s;
-o-transition-property: all;
-o-transition-duration: .2s;
-o-transition-timing-function: linear;
-o-transition-delay: 0s;
}
.manual-article .jump-top .view-backtop.active{
opacity: 0.5;
bottom: 30px;
}
.manual-article .jump-top .view-backtop.active:hover{
background-color: #449D44;
opacity: 1;
}
.m-manual .manual-progress {
position: fixed;
top: 54px;

BIN
static/images/top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

136
utils/ldap.go Normal file
View File

@ -0,0 +1,136 @@
package utils
import (
"gopkg.in/ldap.v2"
"fmt"
"errors"
"github.com/astaxie/beego"
)
/*
对应的config
ldap:
host: hostname.yourdomain.com //ldap服务器地址
port: 3268 //ldap服务器端口
attribute: mail //用户名对应ldap object属性
base: DC=yourdomain,DC=com //搜寻范围
user: CN=ldap helper,OU=yourdomain.com,DC=yourdomain,DC=com //第一次绑定用户
password: p@sswd //第一次绑定密码
ssl: false //使用使用ssl
*/
func ValidLDAPLogin(password string) (result bool, err error) {
result = false
err = nil
lc, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", "192.168.3.104", 389))
if err != nil {
beego.Error("Dial => ",err)
return
}
defer lc.Close()
err = lc.Bind("cn=admin,dc=minho,dc=com", "123456")
if err != nil {
beego.Error("Bind => ",err)
return
}
searchRequest := ldap.NewSearchRequest(
"DC=minho,DC=com",
ldap.ScopeWholeSubtree, ldap.NeverDerefAliases, 0, 0, false,
fmt.Sprintf("(&(objectClass=User)(%s=%s))","mail", "longfei6671@163.com"),
[]string{"dn"},
nil,
)
searchResult, err := lc.Search(searchRequest)
if err != nil {
beego.Error("Search => ", err)
return
}
if len(searchResult.Entries) != 1 {
err = errors.New("ldap.no_user_found_or_many_users_found")
return
}
fmt.Printf("%+v = %d",searchResult.Entries,len(searchResult.Entries))
userdn := searchResult.Entries[0].DN
err = lc.Bind(userdn, password)
if err == nil {
result = true
} else {
beego.Error("Bind2 => ",err)
err = nil
}
return
}
func AddMember(account, password string) error {
lc, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", "192.168.3.104", 389))
if err != nil {
beego.Error("Dial => ",err)
return err
}
defer lc.Close()
user := fmt.Sprintf("cn=%s,dc=minho,dc=com",account)
member := ldap.NewAddRequest(user)
member.Attribute("mail", []string{"longfei6671@163.com"})
err = lc.Add(member)
if err == nil {
err = lc.Bind(user,"")
if err != nil {
beego.Error("Bind => ",err)
return err
}
passwordModifyRequest := ldap.NewPasswordModifyRequest(user, "", "1q2w3e__ABC")
_, err = lc.PasswordModify(passwordModifyRequest)
if err != nil {
beego.Error("PasswordModify => ",err)
return err
}
return nil
}
beego.Error("Add => ",err)
return err
}
func ModifyPassword(account, old_password, new_password string) error {
l, err := ldap.Dial("tcp", fmt.Sprintf("%s:%d", "192.168.3.104", 389))
if err != nil {
beego.Error("Dial => ",err)
}
defer l.Close()
user := fmt.Sprintf("cn=%s,dc=minho,dc=com",account)
err = l.Bind(user, old_password)
if err != nil {
beego.Error("Bind => ",err)
return err
}
passwordModifyRequest := ldap.NewPasswordModifyRequest(user, old_password, new_password)
_, err = l.PasswordModify(passwordModifyRequest)
if err != nil {
beego.Error(fmt.Sprintf("Password could not be changed: %s", err.Error()))
return err
}
return nil
}

View File

@ -179,6 +179,9 @@
</div>
{{end}}
*/}}-->
<div class="jump-top">
<a href="javascript:;" class="view-backtop"><i class="fa fa-arrow-up" aria-hidden="true"></i></a>
</div>
</div>
</div>
@ -281,6 +284,18 @@
}
$(function () {
$(".view-backtop").on("click", function () {
console.log("a")
$('.manual-right').animate({ scrollTop: '0px' }, 200);
});
$(".manual-right").scroll(function () {
var top = $(".manual-right").scrollTop();
if(top > 100){
$(".view-backtop").addClass("active");
}else{
$(".view-backtop").removeClass("active");
}
});
window.isFullScreen = false;
initHighlighting();