示例#1
0
func (u *userReqPutBody) OK() *ae.Error {
	if len(u.FirstName) == 0 {
		return ae.Required("", "first_name")
	} else if len(u.LastName) == 0 {
		return ae.Required("", "last_name")
	} else if !validate.Url(u.ProfilePicURL) {
		return ae.InvalidInput("", "url")
	} else if u.MetricSystem != 1 && u.MetricSystem != 2 {
		return ae.InvalidInput("", "Metric System")
	}
	return nil
}
示例#2
0
func (r *userReqPostBody) OK() *ae.Error {
	if len(r.Email) == 0 && len(r.GoogleKey) == 0 {
		return ae.Required("", "(email and pass) or (google_key)")
	} else if len(r.Email) != 0 {
		if len(r.Password) == 0 {
			return ae.Required("", "password")
		} else if !validate.Email(r.Email) {
			return ae.InvalidInput("", "email")
		} else if !validate.Password(r.Password) {
			return ae.InvalidInput("Invalid Password", "password")
		}
	}

	return nil
}
示例#3
0
func GetUser(w http.ResponseWriter, r *http.Request) {
	userID := context.Get(r, "user_id").(uint64)
	var err error

	urlParams := context.Get(r, "params").(httprouter.Params)
	id := urlParams.ByName("id")
	if len(id) != 0 {
		userID, err = strconv.ParseUint(id, 10, 64)
		if err != nil {
			reply.Err(w, ae.InvalidInput("id is not a number", "id"))
		}
	}

	user := model.User{}
	user.UserID = userID
	err = user.Get()
	if err != nil {
		reply.Err(w, ae.DB("", err))
		return
	}

	reply.OK(w, user)
}