Exemple #1
0
func AuthenticateUser(userDomain *domain.UserDomain, ar domain.AuthenticationRequest, req *http.Request, r render.Render) {
	jwt, err := userDomain.Authenticate(&ar)

	if err != nil {
		r.JSON(400, err.Error())
	} else {
		r.JSON(200, map[string]interface{}{"token": jwt})
	}
}
Exemple #2
0
func GetAuthenticatedUser(userDomain *domain.UserDomain, userUid domain.UserUid, r render.Render) {
	u, err := userDomain.UserByUid(userUid)

	if err != nil {
		r.JSON(400, err.Error())
	} else {
		r.JSON(200, map[string]interface{}{"user": u})
	}
}
Exemple #3
0
// TODO unified error handling
func CreateUser(userDomain *domain.UserDomain, newUser domain.NewUser, req *http.Request, r render.Render) {
	id, err := userDomain.CreateUser(&newUser)

	if err != nil {
		r.JSON(400, err.Error())
	} else {
		r.JSON(200, map[string]interface{}{"id": id})
	}

	return
}