func (r *Registration) HandleRequest(w http.ResponseWriter, req *http.Request) { result := response.NewProfileResponse(0, "") username := req.FormValue("login") password := req.FormValue("password") if username == "" || password == "" { result.Result = 400 result.ResultMessage = "Login and Password are required" } else { profile := models.NewProfile(config.GetConnection()) if profile.FindByUsername(username) == nil { profile.Username = username profile.SetPassword(password) profile.Save() result.Data = profile } else { result.Result = 403 result.ResultMessage = "Account exists" } } jsonResult, err := json.Marshal(result) if err != nil { w.WriteHeader(500) } else { w.Write(jsonResult) } }
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) } }