public async Task <IActionResult> Edit(long id, [Bind("user_id,user_name,email_address,user_password")] User_Admin user_Admin) { if (id != user_Admin.user_id) { return(NotFound()); } if (ModelState.IsValid) { try { user_Admin.user_password = GetHash(user_Admin.user_password); _context.Update(user_Admin); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!User_AdminExists(user_Admin.user_id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user_Admin)); }
public async Task <IActionResult> Login(string email, string password) { User_AdminController _userManager = new User_AdminController(_context); if (!ModelState.IsValid) { return(View()); } try { //authenticate var userdata = new User_Admin() { email_address = email, user_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()); } }
protected void Login_Click(object sender, EventArgs e) { String user = loginType.SelectedValue; int num = 0; Session["uName"] = user; if (user.Equals("UA")) { User_Admin ua = new User_Admin(loginUser.Text, loginPwd.Text); if (ua.validate_UA()) { Response.Redirect("homeUA.aspx"); } else { Label2.Text = "Username or Password is invalid..."; } } else if (user.Equals("TG")) { Tour_Guide tg = new Tour_Guide(loginUser.Text, loginPwd.Text); num = tg.validate_TG(); Session["username"] = loginUser.Text; Session["password"] = loginPwd.Text; if (num == 1) { Response.Redirect("homeTG.aspx"); } else if (num == 2) { Label2.Text = "User is suspended"; } else if (num == 3) { Label2.Text = "Username or Password is invalid..."; } } else if (user.Equals("TR")) { Tourist tr = new Tourist(loginUser.Text, loginPwd.Text); num = tr.validate_TR(); Session["username"] = loginUser.Text; Session["password"] = loginPwd.Text; if (num == 1) { Response.Redirect("homeTR.aspx"); } else if (num == 2) { Label2.Text = "User is suspended"; } else if (num == 3) { Label2.Text = "Username or Password is invalid..."; } } }
private IEnumerable <Claim> GetUserRoleClaims(User_Admin user) { List <Claim> claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.NameIdentifier, user.user_id.ToString())); claims.Add(new Claim("Role", user.user_role.ToString())); return(claims); }
private IEnumerable <Claim> GetUserClaims(User_Admin user) { List <Claim> claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.NameIdentifier, user.user_id.ToString())); claims.Add(new Claim(ClaimTypes.Name, user.user_name)); claims.Add(new Claim(ClaimTypes.Email, user.email_address)); claims.Add(new Claim("Role", user.user_role)); //claims.AddRange(this.GetUserRoleClaims(user)); return(claims); }
public async Task <IActionResult> Create([Bind("user_id,user_name,email_address,user_password")] User_Admin user_Admin) { if (ModelState.IsValid) { user_Admin.user_password = GetHash(user_Admin.user_password); _context.Add(user_Admin); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user_Admin)); }
protected void Suspend_Click(object sender, EventArgs e) { User_Admin ua = new User_Admin(Session["uName"].ToString()); if (ua.suspend_user(suspendUser.Text)) { Label2.Text = suspendUser.Text + " suspended"; } else { Label2.Text = "User does not exist."; } }
//public User_AdminController() //{ //} public async Task SignIn(HttpContext httpContext, User_Admin user, bool isPersistent = false) { user.user_password = GetHash(user.user_password); var user_AdminData = await _context.User_Admin .SingleOrDefaultAsync(m => m.email_address == user.email_address && m.user_password == user.user_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_AdminData.user_id.ToString(), "http://www.w3.org/2001/XMLSchema#string")); claimsIdentity.AddClaim(new Claim(ClaimTypes.Name, user_AdminData.user_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; }
protected void Page_Load(object sender, EventArgs e) { User_Admin ua = new User_Admin(Session["uName"].ToString()); String reader = ua.view_Users(); String[] readerArr = reader.Split(';'); Array.Resize(ref readerArr, readerArr.Length - 1); // remove last element // create new row for adding table heading TableRow tableHeading = new TableRow(); // create and add cells that contain tourist ID TableHeaderCell tidHeading = new TableHeaderCell(); tidHeading.Text = "Tour Guide ID"; tidHeading.HorizontalAlign = HorizontalAlign.Left; tableHeading.Cells.Add(tidHeading); TableHeaderCell tgidHeading = new TableHeaderCell(); tgidHeading.Text = "Tourist ID"; tgidHeading.HorizontalAlign = HorizontalAlign.Left; tableHeading.Cells.Add(tgidHeading); TableHeaderCell userHeading = new TableHeaderCell(); userHeading.Text = "Username"; userHeading.HorizontalAlign = HorizontalAlign.Left; tableHeading.Cells.Add(userHeading); TableHeaderCell susHeading = new TableHeaderCell(); susHeading.Text = "Status"; susHeading.HorizontalAlign = HorizontalAlign.Left; tableHeading.Cells.Add(susHeading); DisplayTable.Rows.Add(tableHeading); // add details to table for (int i = 0; i < readerArr.Length; i++) { TableRow detailsRow = new TableRow(); TableCell tgidCell = new TableCell(); tgidCell.Text = readerArr[i]; detailsRow.Cells.Add(tgidCell); TableCell tidCell = new TableCell(); tidCell.Text = readerArr[++i]; detailsRow.Cells.Add(tidCell); TableCell userCell = new TableCell(); userCell.Text = readerArr[++i]; detailsRow.Cells.Add(userCell); TableCell susCell = new TableCell(); if (readerArr[++i].Equals("true")) { susCell.Text = "Suspended"; } else { susCell.Text = "Active"; } detailsRow.Cells.Add(susCell); DisplayTable.Rows.Add(detailsRow); } }