public FinanceUserViewModel Find(int id) { FinanceUser fUser = _repository.FindOne(a => a.Id == id); FinanceUserViewModel user = new FinanceUserViewModel() { Id = (int)fUser?.Id, Name = fUser?.Name, UserName = fUser?.UserName }; return(user); }
public IHttpActionResult Register([FromBody] LoginData data) { FinanceUserViewModel user = new FinanceUserViewModel() { Name = data.name, Password = data.password, UserName = data.userName }; _userService.AddFinanceUser(user); return(Ok()); }
public void AddFinanceUser(FinanceUserViewModel user) { FinanceUser newUser = new FinanceUser() { Id = user.Id, Name = user.Name, Password = user.Password, UserName = user.UserName }; _repository.Add(newUser); _repository.Save(); }
public ClaimsIdentity GetClaimsIdentity(FinanceUserViewModel user, string authenticationType, string password = null) { ClaimsIdentity identity = new ClaimsIdentity(authenticationType); identity.AddClaim(new Claim(ClaimType.UserIdClaimType.ToString(), user.Id.ToString())); identity.AddClaim(new Claim(ClaimType.UserName.ToString(), user.UserName)); if (password != null) { identity.AddClaim(new Claim(ClaimType.Password.ToString(), password.Encrypt())); } return(identity); }
//TODO: not good! #pragma warning disable 1998 public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) #pragma warning restore 1998 { var userManager = DependencyResolver.Current.GetService <IAppUserManager>(); FinanceUserViewModel user = userManager.Find(context.UserName); if (user == null) { context.SetError("The user was not found in Database."); return; } ClaimsIdentity oAuthIdentity = userManager.GetClaimsIdentity(user, OAuthDefaults.AuthenticationType, context.Password); ClaimsIdentity cookiesIdentity = userManager.GetClaimsIdentity(user, CookieAuthenticationDefaults.AuthenticationType); AuthenticationProperties properties = CreateProperties(user.UserName); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); }
public FinanceUserViewModel Find(string userName) { FinanceUserViewModel user = _userService.Find(userName); return(user); }