Exemplo n.º 1
0
func (this *UpdateController) Post() {
	body := this.Ctx.Input.RequestBody
	beego.Debug("requestBody=", string(body))

	//step 1: get input
	code := &StatusCode{}
	input := &updateInput{}

	if err := json.Unmarshal(body, input); nil != err {
		code.Write(this.Ctx, ErrUmsInputError, err)

		return
	}
	beego.Debug("update input", input)

	//step 2: get and update user(local)
	user := input.UserStatus()
	if nil != user.Get() {
		code.Write(this.Ctx, ErrUmsUserHaveBeenDeauthed, nil)

		return
	}

	input.UpdateUserStatus(user)

	//step 3: radius acct update
	raduser := user.RadUser()

	if err, aerr := radgo.ClientAcctUpdate(raduser); nil != err {
		code.Write(this.Ctx, ErrUmsRadAcctUpdateError, err)

		return
	} else if nil != aerr {
		code.Write(this.Ctx, ErrUmsRadError, aerr)

		return
	}

	//step 4: update user(db)
	if err := user.Update(); nil != err {
		beego.Debug("update", user, err)

		// NOT abort when update error
		// because not keepalive, wait timeout
	} else {
		//keepalive(just update ok)
		mod.AddAlive(user.UserName, user.UserMac)
	}

	//step 5: output
	code.Write(this.Ctx, 0, nil)
}
Exemplo n.º 2
0
Arquivo: auth.go Projeto: tcdog001/ums
func (this *UserAuthController) Post() {
	body := this.Ctx.Input.RequestBody
	beego.Info("request body=", string(body))

	//step 1: get input
	code := &AuthStatusCode{}
	input := &authInput{}

	if err := json.Unmarshal(body, input); err != nil {
		code.Write(this.Ctx, ErrUmsInputError, err)

		return
	}
	input.Init()
	beego.Debug("auth input", input)

	//step 2: check registered
	info := input.UserInfo()
	if !info.IsRegistered() {
		code.Write(this.Ctx, ErrUmsUserInfoNotRegistered, nil)

		return
	}

	//step 3: have authed ?
	user := input.UserStatus()
	if user.Exist() {
		code.Write(this.Ctx, ErrUmsUserHaveAuthed, nil)

		return
	}

	//step 4: radius auth and acct start
	raduser := user.RadUser()

	policy, err, aerr := radgo.ClientAuth(raduser)
	if nil != err {
		code.Write(this.Ctx, ErrUmsRadAuthError, err)

		return
	} else if nil != aerr {
		code.Write(this.Ctx, ErrUmsRadError, aerr)

		return
	}
	beego.Debug("auth received policy:[", policy, "]")

	err, aerr = radgo.ClientAcctStart(raduser)
	if nil != err {
		code.Write(this.Ctx, ErrUmsRadAcctStartError, err)

		return
	} else if nil != aerr {
		code.Write(this.Ctx, ErrUmsRadError, aerr)

		return
	}

	//step 5: register user status
	beego.Debug("user.UserName="******"auth", user, err)

		//radius acct stop when register error
		//user.Reason = int(radgo.DeauthReasonNasError)
		//radgo.ClientAcctStop(raduser)

		code.Write(this.Ctx, ErrUmsUserStatusRegisterError, err)
		return
	}

	//step 6: keepalive(when register ok/fail)
	mod.AddAlive(user.UserName, user.UserMac)

	//step 7: output
	code.WritePolicy(this.Ctx, policy)

	return
}