示例#1
0
func (this *UserController) ChangePassword() {
	oldPassword := strings.TrimSpace(this.GetString("old_password", ""))
	newPassword := strings.TrimSpace(this.GetString("new_password", ""))
	repeatPassword := strings.TrimSpace(this.GetString("repeat_password", ""))

	if newPassword != repeatPassword {
		this.ServeErrJson("password not equal the repeart one")
		return
	}

	me := this.Ctx.Input.GetData("CurrentUser").(*User)
	if me.Passwd != str.Md5Encode(g.Config().Salt+oldPassword) {
		this.ServeErrJson("old password error")
		return
	}

	newPass := str.Md5Encode(g.Config().Salt + newPassword)
	if me.Passwd == newPass {
		this.ServeOKJson()
		return
	}

	me.Passwd = newPass
	_, err := me.Update()
	if err != nil {
		this.ServeErrJson("occur error " + err.Error())
		return
	}

	RemoveSessionByUid(me.Id)
	this.ServeOKJson()
}
示例#2
0
func (this *AuthController) RegisterPost() {
	if !g.Config().CanRegister {
		this.ServeErrJson("registration system is not open")
		return
	}

	name := strings.TrimSpace(this.GetString("name", ""))
	password := strings.TrimSpace(this.GetString("password", ""))
	repeatPassword := strings.TrimSpace(this.GetString("repeat_password", ""))

	if password != repeatPassword {
		this.ServeErrJson("password not equal the repeart one")
		return
	}

	if !utils.IsUsernameValid(name) {
		this.ServeErrJson("name pattern is invalid")
		return
	}

	if ReadUserIdByName(name) > 0 {
		this.ServeErrJson("name is already existent")
		return
	}

	lastId, err := InsertRegisterUser(name, str.Md5Encode(g.Config().Salt+password))
	if err != nil {
		this.ServeErrJson("insert user fail " + err.Error())
		return
	}

	this.CreateSession(lastId, 3600*24*30)

	this.ServeOKJson()
}
示例#3
0
func (this *AuthController) renderLoginPage(sig, callback string) {
	this.Data["CanRegister"] = g.Config().CanRegister
	this.Data["LdapEnabled"] = g.Config().Ldap.Enabled
	this.Data["Sig"] = sig
	this.Data["Callback"] = callback
	this.TplNames = "auth/login.html"
}
示例#4
0
func (this *UserController) CreateUserPost() {
	me := this.Ctx.Input.GetData("CurrentUser").(*User)
	if me.Role <= 0 {
		this.ServeErrJson("no privilege")
		return
	}

	name := strings.TrimSpace(this.GetString("name", ""))
	password := strings.TrimSpace(this.GetString("password", ""))
	role, _ := this.GetInt("role", -1)

	if !utils.IsUsernameValid(name) {
		this.ServeErrJson("name pattern is invalid")
		return
	}

	if ReadUserIdByName(name) > 0 {
		this.ServeErrJson("name is already existent")
		return
	}

	_, err := InsertUser(name, str.Md5Encode(g.Config().Salt+password), role)
	if err != nil {
		this.ServeErrJson("insert user fail " + err.Error())
	} else {
		this.ServeOKJson()
	}
}
示例#5
0
文件: http.go 项目: gaochao1/fe
func Start() {
	if !g.Config().Http.Enabled {
		return
	}

	addr := g.Config().Http.Listen
	if addr == "" {
		return
	}

	home.ConfigRoutes()
	uic.ConfigRoutes()

	beego.AddFuncMap("member", uic_model.MembersByTeamId)
	beego.Run(addr)
}
示例#6
0
文件: database.go 项目: gaochao1/fe
func InitDatabase() {
	// set default database
	config := g.Config()
	orm.RegisterDataBase("default", "mysql", config.Uic.Addr, config.Uic.Idle, config.Uic.Max)

	// register model
	orm.RegisterModel(new(User), new(Team), new(Session), new(RelTeamUser))

	if config.Log == "debug" {
		orm.Debug = true
	}
}
示例#7
0
文件: cache.go 项目: gaochao1/fe
func InitCache() {
	cfg := g.Config()
	if !cfg.Cache.Enabled {
		return
	}

	cache.InitCache(
		cfg.Cache.Redis,
		cfg.Cache.Idle,
		cfg.Cache.Max,
		time.Duration(cfg.Cache.Timeout.Conn)*time.Millisecond,
		time.Duration(cfg.Cache.Timeout.Read)*time.Millisecond,
		time.Duration(cfg.Cache.Timeout.Write)*time.Millisecond,
		time.Hour,
	)
}
示例#8
0
func (this *UserController) CreateRoot() {
	password := strings.TrimSpace(this.GetString("password", ""))
	if password == "" {
		this.Ctx.Output.Body([]byte("password is blank"))
		return
	}

	userPtr := &User{
		Name:   "root",
		Passwd: str.Md5Encode(g.Config().Salt + password),
		Role:   2,
	}

	_, err := userPtr.Save()
	if err != nil {
		this.Ctx.Output.Body([]byte(err.Error()))
	} else {
		this.Ctx.Output.Body([]byte("success"))
	}
}
示例#9
0
func (this *UserController) ResetPassword() {
	password := this.GetString("password", "")
	if password == "" {
		this.ServeErrJson("password is blank")
		return
	}

	targetUser := this.Ctx.Input.GetData("TargetUser").(*User)
	if targetUser.Name == "root" {
		this.ServeErrJson("no privilege")
		return
	}

	targetUser.Passwd = str.Md5Encode(g.Config().Salt + password)
	_, err := targetUser.Update()
	if err != nil {
		this.ServeErrJson("occur error " + err.Error())
		return
	}

	this.ServeOKJson()
}
示例#10
0
文件: main.go 项目: gaochao1/fe
func main() {
	cfg := flag.String("c", "cfg.json", "configuration file")
	version := flag.Bool("v", false, "show version")
	flag.Parse()

	if *version {
		fmt.Println(g.VERSION)
		os.Exit(0)
	}

	// parse config
	if err := g.ParseConfig(*cfg); err != nil {
		log.Fatalln(err)
	}

	logger.SetLevelWithDefault(g.Config().Log, "info")

	model.InitDatabase()
	cache.InitCache()

	http.Start()
}
示例#11
0
func (this *AuthController) LoginPost() {
	name := this.GetString("name", "")
	password := this.GetString("password", "")

	if name == "" || password == "" {
		this.ServeErrJson("name or password is blank")
		return
	}

	var u *User

	ldapEnabled := this.MustGetBool("ldap", false)

	if ldapEnabled {
		sucess, err := utils.LdapBind(g.Config().Ldap.Addr, name, password)
		if err != nil {
			this.ServeErrJson(err.Error())
			return
		}

		if !sucess {
			this.ServeErrJson("name or password error")
			return
		}

		arr := strings.Split(name, "@")
		var userName, userEmail string
		if len(arr) == 2 {
			userName = arr[0]
			userEmail = name
		} else {
			userName = name
			userEmail = ""
		}

		u = ReadUserByName(userName)
		if u == nil {
			// 说明用户不存在
			u = &User{
				Name:   userName,
				Passwd: "",
				Email:  userEmail,
			}
			_, err = u.Save()
			if err != nil {
				this.ServeErrJson("insert user fail " + err.Error())
				return
			}
		}
	} else {
		u = ReadUserByName(name)
		if u == nil {
			this.ServeErrJson("no such user")
			return
		}

		if u.Passwd != str.Md5Encode(g.Config().Salt+password) {
			this.ServeErrJson("password error")
			return
		}
	}

	expired := this.CreateSession(u.Id, 3600*24*30)

	appSig := this.GetString("sig", "")
	callback := this.GetString("callback", "")
	if appSig != "" && callback != "" {
		SaveSessionAttrs(u.Id, appSig, expired)
	}

	this.ServeDataJson(callback)
}
示例#12
0
func (this *AuthController) RegisterGet() {
	this.Data["CanRegister"] = g.Config().CanRegister
	this.TplNames = "auth/register.html"
}
示例#13
0
func (this *UserController) QrCode() {
	idStr := this.Ctx.Input.Param(":id")
	id, err := strconv.ParseInt(idStr, 10, 64)
	if err != nil {
		this.NotFound("no such user")
		return
	}

	u := ReadUserById(id)
	if u == nil {
		this.NotFound("no such user")
		return
	}

	c, err := qr.Encode("BEGIN:VCARD\nVERSION:3.0\nFN:"+u.Cnname+"\nTEL;WORK;VOICE:"+u.Phone+"\nEMAIL;PREF;INTERNET:"+u.Email+"\nORG:"+g.Config().Company+"\nEND:VCARD", qr.L)
	if err != nil {
		this.NotFound("no such user")
		return
	}

	this.Ctx.Output.ContentType("image")
	this.Ctx.Output.Body(c.PNG())
}
示例#14
0
func (this *HomeController) Get() {
	this.Data["Shortcut"] = g.Config().Shortcut
	this.TplNames = "home/index.html"
}