func UserLogin(w http.ResponseWriter, r *http.Request) {
	var login types.LoginRequest
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	w.Header().Set("X-Api-Correlation-Id", "1234")

	body, err := ioutil.ReadAll(r.Body)
	defer r.Body.Close()

	if err != nil {
		w.WriteHeader(http.StatusServiceUnavailable)
		return
	}

	err = json.Unmarshal(body, &login)
	if err != nil {
		w.WriteHeader(http.StatusServiceUnavailable)
		return
	}

	user, err := userRepository.ByUsername(login.Username)
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
	} else if user.Username != login.Username || user.Password != login.Password {
		w.WriteHeader(http.StatusUnauthorized)
	} else {
		w.Header().Set("X-Auth-Token", getAuthToken())
		w.WriteHeader(http.StatusOK)
		res := types.LoginResponse{User: user}
		resBody, _ := json.Marshal(res)
		w.Write(resBody)
	}
}
func UserLogin(w http.ResponseWriter, r *http.Request) {
	var login types.LoginRequest
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	w.Header().Set("X-Api-Correlation-Id", "1234")

	body, err := ioutil.ReadAll(r.Body)
	defer r.Body.Close()

	if err != nil {
		w.WriteHeader(http.StatusServiceUnavailable)
		return
	}

	err = json.Unmarshal(body, &login)
	if err != nil {
		w.WriteHeader(http.StatusServiceUnavailable)
		return
	}

	user, err := userRepository.ByUsername(login.Username)
	if err != nil {
		w.WriteHeader(http.StatusNotFound)
	} else if user.Username != login.Username || user.Password != login.Password {
		w.WriteHeader(http.StatusUnauthorized)
	} else {
		w.Header().Set("X-Auth-Token", getAuthToken())
		w.WriteHeader(http.StatusOK)
		res := types.LoginResponse{User: user}
		resBody, _ := json.Marshal(res)
		w.Write(resBody)
	}
}
func UserLogin ( w http . ResponseWriter , r * http . Request ) { var login types . LoginRequest w . Header ( ) . Set ( " " , " " ) w . Header ( ) . Set ( " " , " " ) body , err := ioutil . ReadAll ( r . Body ) defer r . Body . Close ( ) if err != nil { w . WriteHeader ( http . StatusServiceUnavailable ) return } err = json . Unmarshal ( body , & login ) if err != nil { w . WriteHeader ( http . StatusServiceUnavailable ) return } user , err := userRepository . ByUsername ( login . Username ) if err != nil { w . WriteHeader ( http . StatusNotFound ) } else if user . Username != login . Username || user . Password != login . Password { w . WriteHeader ( http . StatusUnauthorized ) } else { w . Header ( ) . Set ( " " , getAuthToken ( ) ) w . WriteHeader ( http . StatusOK ) res := types . LoginResponse { User : user } resBody , _ := json . Marshal ( res ) w . Write ( resBody ) } }
// UserLogin logs a user in, returning an auth token and the user object
UserLogin logs a user in returning an auth token and the user object