Exemple #1
0
 public TokenWithUserBaseModel Login(UserModel model)
 {
     if (model == null)
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     try {
         string token = manager.checkUser(model.Email, model.Password);
         if (token != null)
         {
             return new TokenWithUserBaseModel(token, manager.get(model.Email));
         }
     }
     catch
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
     throw new HttpResponseException(HttpStatusCode.Unauthorized);
 }
 public TokenModel Register(UserModel model)
 {
     if (model == null)
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     try
     {
         USER objBdd = new USER();
         objBdd.FIRST_NAME = model.FirstName;
         objBdd.LAST_NAME = model.Lastname;
         objBdd.ID_AGENCY = model.Agency.Id;
         objBdd.EMAIL = model.Email;
         objBdd.PASSWORD = model.Password;
         objBdd.DESCRIPTION = "";
         manager.add(objBdd);
         Guid guid = Guid.NewGuid();
         return new TokenModel(manager.addSession(objBdd.ID_USER));
     }
     catch
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     }
     throw new HttpResponseException(HttpStatusCode.Unauthorized);
 }
Exemple #3
0
 // POST api/values
 public HttpResponseMessage Post(UserModel model)
 {
     if (HttpContext.Current.Request.Headers["Authorization"] == null)
     {
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
     USER objBdd = new USER();
     objBdd.FIRST_NAME = model.FirstName;
     objBdd.LAST_NAME = model.Lastname;
     objBdd.ID_AGENCY = model.Agency.Id;
     objBdd.EMAIL = model.Email;
     objBdd.PASSWORD = model.Password;
     objBdd.DESCRIPTION = model.Description;
     manager.add(objBdd);
     return new HttpResponseMessage()
     {
         Content = new JsonContent(new
         {
             Success = true, //error
             Message = "Success" //return exception
         })
     };
 }