public async Task <IActionResult> Login(string email, string password) { Service_ProviderController _userManager = new Service_ProviderController(_context); if (!ModelState.IsValid) { return(View()); } try { //authenticate var userdata = new Service_Provider() { sp_mobile = email, sp_password = password }; //var result = new User_AdminController(_context).SignIn(HttpContext, userdata); //RedirectToAction("../{User_AdminController}/SignIn", new { httpContext = this.HttpContext, user= userdata }); await _userManager.SignIn(this.HttpContext, userdata); if (!this.HttpContext.User.Identity.IsAuthenticated) { } return(RedirectToAction("Index", "Order_Header", null)); } catch (Exception ex) { ModelState.AddModelError("summary", ex.Message); return(View()); } }
public async Task <IActionResult> Edit(long id, [Bind("sp_id,sp_name,sp_add_details,sp_registration_no,sp_fb,sp_google,sp_phone,sp_mobile,sp_password,sp_status,sp_add_1,sp_add_2,sp_add_3,sp_post,created_date")] Service_Provider service_Provider) { if (id != service_Provider.sp_id) { return(NotFound()); } if (ModelState.IsValid) { try { service_Provider.sp_password = GetHash(service_Provider.sp_password); service_Provider.update_date = DateTime.Now; _context.Update(service_Provider); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Service_ProviderExists(service_Provider.sp_id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(service_Provider)); }
private IEnumerable <Claim> GetUserRoleClaims(Service_Provider user) { List <Claim> claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.NameIdentifier, user.sp_mobile.ToString())); //claims.Add(new Claim("Role", user.user_role.ToString())); return(claims); }
public async Task <IActionResult> Create([Bind("sp_id,sp_name,sp_add_details,sp_registration_no,sp_fb,sp_google,sp_phone,sp_mobile,sp_password,sp_status,sp_add_1,sp_add_2,sp_add_3,sp_post")] Service_Provider service_Provider) { if (ModelState.IsValid) { service_Provider.created_date = DateTime.Now; service_Provider.update_date = DateTime.Now; _context.Add(service_Provider); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(service_Provider)); }
public async Task SignIn(HttpContext httpContext, Service_Provider user, bool isPersistent = false) { user.sp_password = GetHash(user.sp_password); var user_SPData = await _context.Service_Provider .SingleOrDefaultAsync(m => m.sp_mobile == user.sp_mobile && m.sp_password == user.sp_password); //ClaimsIdentity identity = new ClaimsIdentity(this.GetUserClaims(user_AdminData), CookieAuthenticationDefaults.AuthenticationScheme); ClaimsIdentity claimsIdentity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.NameIdentifier, ClaimTypes.Role); claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user_SPData.sp_id.ToString(), "http://www.w3.org/2001/XMLSchema#string")); claimsIdentity.AddClaim(new Claim(ClaimTypes.Name, user_SPData.sp_name.ToString(), "http://www.w3.org/2001/XMLSchema#string")); claimsIdentity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "Custom Identity", "http://www.w3.org/2001/XMLSchema#string")); ClaimsPrincipal principal = new ClaimsPrincipal(claimsIdentity); //AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); await httpContext.SignInAsync(principal); httpContext.User = principal; string aaa = httpContext.User.Identity.Name; string bbb = httpContext.User.Identity.GetUserName(); string ccc = httpContext.User.Identity.GetUserId(); }