public Task<User> GetUserByName(string userName) { using (var context = new AngularTemplateEntities()) { var user = context.Users.Where(u => u.UserName == userName).FirstOrDefault(); return Task.FromResult(user); } }
public Task<User> RegisterUser(string userName, string password, string fullName) { using (var context = new AngularTemplateEntities()) { var token = UserSecurity.EncryptText(userName, password); var user = new User { UserName = userName, FullName = fullName, Token = token, PasswordResetRequired = false }; context.Users.Add(user); context.SaveChanges(); return Task.FromResult(user); } }
public Task<User> AuthenticateUser(string userName, string password) { var token = UserSecurity.EncryptText(userName, password); using (var context = new AngularTemplateEntities()) { var user = context.Users.Where(u => u.UserName == userName).FirstOrDefault(); if (user == null) user.Id = -1; // user not found if (user.Token == token) user.Id = 0; // user found, token not matching if (user.Id <= 0) user.FullName = string.Empty; return Task.FromResult(user); } }