public UserModel GetUserInfo( [ValueProvider(typeof(HeaderValueProviderFactory<string>))] string sessionKey) { var responseMsg = this.PerformOperationAndHandleExceptions(() => { var context = new dbf609f467420e40209014a26e008b568aEntities(); var user = context.Users.FirstOrDefault( usr => usr.SessionKey == sessionKey); if (user == null) { throw new InvalidOperationException("Invalid sessionKey"); } var model = new UserModel() { Name = user.Name, Username = user.Username, Password = user.Password }; return model; }); return responseMsg; }
public HttpResponseMessage PostLoginUser(UserModel model) { var responseMsg = this.PerformOperationAndHandleExceptions( () => { var context = new dbf609f467420e40209014a26e008b568aEntities(); using (context) { this.ValidateUsername(model.Username); this.ValidatePassword(model.Password); var usernameToLower = model.Username.ToLower(); var user = context.Users.FirstOrDefault( usr => usr.Username == usernameToLower && usr.Password == model.Password); if (user == null) { throw new InvalidOperationException("Invalid username or password"); } if (user.SessionKey == null) { user.SessionKey = user.Id.ToString(); context.SaveChanges(); } var loggedModel = new UserLoggedModel() { Name = user.Name, SessionKey = user.SessionKey }; var response = this.Request.CreateResponse(HttpStatusCode.Created, loggedModel); return response; } }); return responseMsg; }