Ejemplo n.º 1
0
func RegisterUser(userData database.UserData, userId string, password string) int {
	if len(userId) > 0 && len(password) > 0 {
		userObj, _ := NewUser(userId, password)
		// Check if user already exists
		user, err := userData.GetUser(userObj.GetUserId())
		if user != nil {
			log.Warning("Duplicate username tried: %s", userId)
			return http.StatusConflict
		}
		// Save User to database
		err = userData.SaveUser(userObj.GetUserId(), userObj.GetPasswordHash())
		if err != nil {
			log.Warning("Unable to create user: %s", err.Error())
			return http.StatusInternalServerError
		} else {
			return http.StatusOK
		}
	} else {
		log.Debug("Unable to create user, username or password missing")
		return http.StatusBadRequest
	}
}