Esempio n. 1
0
func (r Login) HandleRequest(w http.ResponseWriter, req *http.Request) {
	result := response.NewProfileResponse(0, "")

	login := req.FormValue("login")
	password := req.FormValue("password")

	if login == "" || password == "" {
		w.WriteHeader(400)
		result.Result = 400
		result.ResultMessage = "Login and Password are required"
	} else {
		profile := models.NewProfile(config.GetConnection()).FindByCredentials(login, helpers.GetMD5(password))

		result.Data = profile
	}

	jsonResult, err := json.Marshal(result)

	if err != nil {
		w.WriteHeader(500)
	} else {
		w.Write(jsonResult)
	}
}
Esempio n. 2
0
/**
* Set password
 */
func (p *Profile) SetPassword(password string) {
	p.password = helpers.GetMD5(password)
}