Exemplo n.º 1
0
 public APIUserResponse Authenticate(string Email, string Password)
 {
     a5js_apiEntities db = new a5js_apiEntities();
     User user = (from u in db.Users where u.Email == Email && u.Password == Password select u).FirstOrDefault();
     if (user != null) {
         string token = Guid.NewGuid().ToString();
         db.Sessions.Add(new Session() {
             UserID = user.UserID,
             Identifier = token
         });
         db.SaveChanges();
         return new APIUserResponse(APIResponseStatus.SUCCESS, APIUserResponseStatus.SUCCESS, token);
     } else {
         return new APIUserResponse(APIResponseStatus.SUCCESS, APIUserResponseStatus.INVALID_CREDENTIALS);
     }
 }