コード例 #1
0
ファイル: user.go プロジェクト: kwangyoung/go-messenger
func DeleteUser(userData database.UserData, userId string, password string) int {
	if len(userId) > 0 && len(password) > 0 {
		passwordHash, _ := userData.GetUser(userId)
		if passwordHash == nil {
			log.Warning("User not found, cannot delete: %s", userId)
			return http.StatusNotFound
		} else {
			if CompareHashAndPassword(passwordHash, password) == nil {
				userData.DeleteUser(userId)
				return http.StatusOK
			} else {
				return http.StatusBadRequest
			}

		}
	} else {
		log.Debug("Unable to delete user, username or password missing")
		return http.StatusBadRequest
	}
}
コード例 #2
0
ファイル: user.go プロジェクト: kwangyoung/go-messenger
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
	}
}