Beispiel #1
0
func (user *User) IsEmailExist(request *restful.Request, response *restful.Response) {
	user.Email = strings.TrimSpace(request.HeaderParameter("email"))

	if !helpers.IsAConformEmail(user.Email) {
		response.WriteHeader(http.StatusNotAcceptable)
		helpers.PrintLog(request, response, user.Name)
		return
	}
	if user.GetUserByEmail() == false {
		response.WriteHeader(http.StatusNotFound)
	} else {
		response.WriteHeader(http.StatusOK)
	}
	helpers.PrintLog(request, response, user.Name)
}
Beispiel #2
0
func (user *User) checkEmail(request *restful.Request, response *restful.Response, chain *restful.FilterChain) {
	errors := api.Error{}

	//check email's format
	if !helpers.IsAConformEmail(user.Email) {
		errors.ListErrors = append(errors.ListErrors, "Email address isn't in right format")
		response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
		helpers.PrintLog(request, response, user.Name)
		return
	}

	if user.GetUserByEmail() == true {
		errors.ListErrors = append(errors.ListErrors, "Email address is already used")
		response.WriteHeaderAndEntity(http.StatusNotAcceptable, errors)
		helpers.PrintLog(request, response, user.Name)
		return
	}
	chain.ProcessFilter(request, response)
}