Esempio n. 1
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()
}
Esempio n. 2
0
func (this *AuthApiController) Register() {
	baseResp := this.BasicRespGen()
	if !g.Config().CanRegister {
		this.ResposeError(baseResp, "registration system is not open")
		return
	}

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

	var lastID int64
	var err error
	switch {
	case password != repeatPassword:
		this.ResposeError(baseResp, "password not equal the repeart one")
		return
	case !utils.IsUsernameValid(name):
		this.ResposeError(baseResp, "name pattern is invalid")
		return
	case ReadUserIdByName(name) > 0:
		this.ResposeError(baseResp, "name is already existent")
		return
	default:
		lastID, err = InsertRegisterUser(name, str.Md5Encode(g.Config().Salt+password), email)
		if err != nil {
			this.ResposeError(baseResp, "insert user fail "+err.Error())
			return
		}
	}

	sig, expired := this.CreateSession(lastID, 3600*24*30)
	baseResp.Data["name"] = name
	baseResp.Data["sig"] = sig
	baseResp.Data["expired"] = expired
	this.ServeApiJson(baseResp)
	return
}
Esempio n. 3
0
func (this *UserController) CreateUserPost() {
	name := strings.TrimSpace(this.GetString("name", ""))
	password := strings.TrimSpace(this.GetString("password", ""))
	cnname := strings.TrimSpace(this.GetString("cnname", ""))
	email := strings.TrimSpace(this.GetString("email", ""))
	phone := strings.TrimSpace(this.GetString("phone", ""))
	im := strings.TrimSpace(this.GetString("im", ""))
	qq := strings.TrimSpace(this.GetString("qq", ""))

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

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

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

	if utils.HasDangerousCharacters(cnname) {
		this.ServeErrJson("cnname is invalid")
		return
	}

	if utils.HasDangerousCharacters(email) {
		this.ServeErrJson("email is invalid")
		return
	}

	if utils.HasDangerousCharacters(phone) {
		this.ServeErrJson("phone is invalid")
		return
	}

	if utils.HasDangerousCharacters(im) {
		this.ServeErrJson("im is invalid")
		return
	}

	if utils.HasDangerousCharacters(qq) {
		this.ServeErrJson("qq is invalid")
		return
	}

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

	targetUser := ReadUserById(lastId)
	targetUser.Cnname = cnname
	targetUser.Email = email
	targetUser.Phone = phone
	targetUser.IM = im
	targetUser.QQ = qq

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

	this.ServeOKJson()
}