func (s *AuthServer) CreateUserWithToken(token, password, hotpToken string) (*Session, error) {
	err := s.AcquireLock("signuptoken"+token, time.Hour)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	defer func() {
		err := s.ReleaseLock("signuptoken" + token)
		if err != nil {
			log.Errorf(err.Error())
		}
	}()

	tokenData, err := s.GetSignupToken(token)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	otp, err := hotp.Unmarshal(tokenData.Hotp)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	ok := otp.Scan(hotpToken, defaults.HOTPFirstTokensRange)
	if !ok {
		return nil, trace.BadParameter("wrong HOTP token")
	}

	_, _, err = s.UpsertPassword(tokenData.User.GetName(), []byte(password))
	if err != nil {
		return nil, trace.Wrap(err)
	}

	// apply user allowed logins
	if err = s.UpsertUser(&tokenData.User); err != nil {
		return nil, trace.Wrap(err)
	}

	err = s.UpsertHOTP(tokenData.User.GetName(), otp)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	log.Infof("[AUTH] created new user: %v", &tokenData.User)

	if err = s.DeleteSignupToken(token); err != nil {
		return nil, trace.Wrap(err)
	}

	sess, err := s.NewWebSession(tokenData.User.GetName())
	if err != nil {
		return nil, trace.Wrap(err)
	}

	err = s.UpsertWebSession(tokenData.User.GetName(), sess, WebSessionTTL)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	sess.WS.Priv = nil
	return sess, nil
}
// CreateUserWithToken creates account with provided token and password.
// Account username and hotp generator are taken from token data.
// Deletes token after account creation.
CreateUserWithToken creates account with provided token and password.
Account username and hotp generator are taken from token data.
Deletes token after account creation.
// CreateUserWithToken creates account with provided token and password . // Account username and hotp generator are taken from token data . // Deletes token after account creation .
func (s *AuthServer) CreateUserWithToken(token, password, hotpToken string) (*Session, error) {
	err := s.AcquireLock("signuptoken"+token, time.Hour)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	defer func() {
		err := s.ReleaseLock("signuptoken" + token)
		if err != nil {
			log.Errorf(err.Error())
		}
	}()
	tokenData, err := s.GetSignupToken(token)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	otp, err := hotp.Unmarshal(tokenData.Hotp)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	ok := otp.Scan(hotpToken, defaults.HOTPFirstTokensRange)
	if !ok {
		return nil, trace.BadParameter("wrong HOTP token")
	}
	_, _, err = s.UpsertPassword(tokenData.User.GetName(), []byte(password))
	if err != nil {
		return nil, trace.Wrap(err)
	}
	if err = s.UpsertUser(&tokenData.User); err != nil {
		return nil, trace.Wrap(err)
	}
	err = s.UpsertHOTP(tokenData.User.GetName(), otp)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	log.Infof("[AUTH] created new user: %v", &tokenData.User)
	if err = s.DeleteSignupToken(token); err != nil {
		return nil, trace.Wrap(err)
	}
	sess, err := s.NewWebSession(tokenData.User.GetName())
	if err != nil {
		return nil, trace.Wrap(err)
	}
	err = s.UpsertWebSession(tokenData.User.GetName(), sess, WebSessionTTL)
	if err != nil {
		return nil, trace.Wrap(err)
	}
	sess.WS.Priv = nil
	return sess, nil
}
func ( s * AuthServer ) CreateUserWithToken ( token , password , hotpToken string ) ( * Session , error ) { err := s . AcquireLock ( " " + token , time . Hour ) if err != nil { return nil , trace . Wrap ( err ) } defer func ( ) { err := s . ReleaseLock ( " " + token ) if err != nil { log . Errorf ( err . Error ( ) ) } } ( ) tokenData , err := s . GetSignupToken ( token ) if err != nil { return nil , trace . Wrap ( err ) } otp , err := hotp . Unmarshal ( tokenData . Hotp ) if err != nil { return nil , trace . Wrap ( err ) } ok := otp . Scan ( hotpToken , defaults . HOTPFirstTokensRange ) if ! ok { return nil , trace . BadParameter ( " " ) } _ , _ , err = s . UpsertPassword ( tokenData . User . GetName ( ) , [ ] byte ( password ) ) if err != nil { return nil , trace . Wrap ( err ) } if err = s . UpsertUser ( & tokenData . User ) ; err != nil { return nil , trace . Wrap ( err ) } err = s . UpsertHOTP ( tokenData . User . GetName ( ) , otp ) if err != nil { return nil , trace . Wrap ( err ) } log . Infof ( " " , & tokenData . User ) if err = s . DeleteSignupToken ( token ) ; err != nil { return nil , trace . Wrap ( err ) } sess , err := s . NewWebSession ( tokenData . User . GetName ( ) ) if err != nil { return nil , trace . Wrap ( err ) } err = s . UpsertWebSession ( tokenData . User . GetName ( ) , sess , WebSessionTTL ) if err != nil { return nil , trace . Wrap ( err ) } sess . WS . Priv = nil return sess , nil }
CreateUserWithToken creates account with provided token and password.
CreateUserWithToken creates account with provided token and password .
// apply user allowed logins