public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DetailsViewModel model = new DetailsViewModel(); AppUser user = _userManager.Find(x => x.Id == id); if (user == null) { return(HttpNotFound()); } model.User = user; model.Comments = user.Comments; model.Likes = user.Likes; model.LastVisits = user.LastVisits; model.Roles = user.UserRoles.Select(x => x.AppRole).ToList(); model.Logs = _logManager.ListQueryable().Where(x => x.Username == user.Username).ToList(); return(View(model)); }
public ActionResult MyInfo() { MyInfoViewModel model = new MyInfoViewModel(); model.User = _userManager.Find(x => x.Id == CurrentSession.User.Id); return(View(model)); }
public ActionResult RemoveUser(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var user = _userManager.Find(x => x.Id == id); if (user == null) { return(HttpNotFound()); } return(View(user)); }
public async Task <IHttpActionResult> Login(LoginUserBindingModel loginUserModel) { LogInfo("Login attempt", loginUserModel); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApplicationUser lookup = AppUserManager.Find(loginUserModel.UserName, loginUserModel.Password); LogInfo("Login lookup", lookup); var loginResult = new LoginResponse(); if (lookup != null && lookup.EmailConfirmed) { LogInfo("Login success", null); loginResult.token = await GenerateUserToken(lookup); loginResult.user = TheModelFactory.Create(lookup, UserExtManager.UserExtensions.Where(e => e.UserId == lookup.Id).FirstOrDefault()); loginResult.httpResult = Convert.ToInt16(System.Net.HttpStatusCode.OK); return(Json <LoginResponse>(loginResult)); } else { return(StatusCode(System.Net.HttpStatusCode.Unauthorized)); } }
public LoginUser Login(LoginViewModel viewModel, AppUserManager appUserManager) { if (string.IsNullOrWhiteSpace(viewModel.LoginId)) { return(null); } if (string.IsNullOrWhiteSpace(viewModel.Password)) { return(null); } // ログイン可能なユーザーがいるか確認する LoginUser loginUser = appUserManager.Find(viewModel.LoginId, viewModel.Password); return(loginUser); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { AppUserManager UserManager = new AppUserManager(new UserStore <AppUser>(CreateCallback.Invoke())); context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); if (String.IsNullOrEmpty(context.Password) == true || UserManager.Find(context.UserName, context.Password) == null) { context.SetError("invalid_grant", "The user name or password is incorrect."); return; } var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim("sub", context.UserName)); identity.AddClaim(new Claim("role", "user")); context.Validated(identity); }
public string LoginUser(AppUser guest, IAuthenticationManager manager, AppIdentityDbContext db) { AppUserManager userMgr = new AppUserManager(new UserStore <AppUser>(db)); AppUser user = userMgr.Find(guest.UserName, guest.Password); if (user == null) { return("Некорректное имя или пароль"); } else { ClaimsIdentity identity = userMgr.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); manager.SignOut(); manager.SignIn(new AuthenticationProperties { IsPersistent = false }, identity); return(string.Empty); } }
/// <summary> /// Method login logs in user after inserting user name and password /// </summary> /// <param name="userName">User's user name</param> /// <param name="password">User's password</param> /// <returns>Logged in user</returns> public ClaimsIdentity Login(string userName, string password) { var userManager = new AppUserManager(new AppUserStore(new AppDbContext())); var wantedUser = userManager.FindByName(userName); if (wantedUser == null) { return(null); } AppUser user = userManager.Find(wantedUser.UserName, password); if (user == null) { return(null); } return(userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie)); }
public ClaimsIdentity Login(string email, string password) { var userManager = new AppUserManager(new AppUserStore(new AppDbContext())); try { var wantedUser = userManager.FindByEmail(email); if (wantedUser == null) { return(null); } var user = userManager.Find(wantedUser.UserName, password); return(user == null ? null : userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie)); } catch { return(null); } }
// GET: User/Home public ActionResult Index(int Page = 1, int?Category = -1) { var user = _userManager.Find(x => x.Username == "userauthor20"); CurrentSession.Set <AppUser>("login", user); if (Category == null || Category == -1) { ViewBag.CategoryId = null; var blogs = CacheHelper.GetBlogsWithOutDraftDeleteFromCache().ToPagedList(Page, 5); return(View(blogs)); } else { var category = _categoryManager.Find(x => x.Id == Category); if (category == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.CategoryId = Category; var catBlogs = _blogCategoryManager.ListQueryable().Where(x => x.CategoryId == Category).Select(u => u.Blog).ToList(); var blogs = catBlogs.Where(x => x.IsDelete == false && x.IsDraft == false).ToList().ToPagedList(Page, 5); foreach (var item in blogs) { item.Text = HttpUtility.HtmlDecode(item.Text); } return(View(blogs)); } }
protected override void Seed(AppDbContext context) { Settings currentSettings = context.Settings.FirstOrDefault(); if (currentSettings == null) { Settings settings = new Settings() { Currency = "USD", ShopName = "My Demo Shop", ContactEmailAddress = "*****@*****.**", NotificationReplyEmail = "*****@*****.**", SMTPEnableSSL = false }; context.Settings.Add(settings); } AppUserManager userManager = new AppUserManager(new UserStore <AppUser>(context), null); AppRoleManager roleManager = new AppRoleManager(new RoleStore <AppRole>(context)); string roleName = "Administrators"; string userName = "******"; string password = "******"; string email = "*****@*****.**"; if (!roleManager.RoleExists(roleName)) { roleManager.Create(new AppRole(roleName)); } if (!roleManager.RoleExists("Staff")) { roleManager.Create(new AppRole("Staff")); } AppUser user = userManager.FindByEmail(email); if (user == null) { AppUser newUser = new AppUser { Name = userName, Surname = userName, UserName = email, Email = email, Created = DateTime.UtcNow, EmailConfirmed = true }; newUser.Carts = new Collection <Cart> { new Cart(newUser) }; IdentityResult result = userManager.Create(newUser, password); user = userManager.Find(email, password); } if (!userManager.IsInRole(user.Id, roleName)) { userManager.AddToRole(user.Id, roleName); } context.SaveChanges(); }
public IdentityUser FindUser(string username, string password) { IdentityUser user = _userManager.Find(username, password); return(user); }