public IActionResult Login(string email, string pw) { sqlUser existinguser = _context.usertable.Where(a => a.email == email).SingleOrDefault(); if (existinguser != null && pw != null) { //if that email exists PasswordHasher <sqlUser> Hasher = new PasswordHasher <sqlUser>(); //passwordhasher for sqluser if (0 != Hasher.VerifyHashedPassword(existinguser, existinguser.pw, pw)) { //if not 0 meaning password matched HttpContext.Session.SetString("username", existinguser.name); HttpContext.Session.SetInt32("userid", existinguser.id); return(RedirectToAction("Board")); } else { ViewBag.email2 = "Email is found but password does not match."; return(View("Index")); } } else { ViewBag.email2 = "Email is NOT found AND password does not match."; return(View("Index")); } }
[HttpPost("register")] //must be same as asp-action public IActionResult register(Userlogin newuser) { sqlUser validuser = _context.usertable.SingleOrDefault(a => a.email == newuser.email); //.email is existing usertable email list if (validuser != null) { // != email is taken ViewBag.email = "This email is taken. Try another email."; return(View("Index")); } if (ModelState.IsValid != true && validuser != null) { //not valid (error msg will show) & taken email ViewBag.email = "This email is taken. Try another email."; return(View("Index")); } if (ModelState.IsValid) { // transfer the form user to sqluser model, which graps the table from the usertable. copy.name is the usertable's name. sqlUser copy = new sqlUser(); copy.name = newuser.name; copy.lastname = newuser.lastname; copy.email = newuser.email; copy.pw = newuser.pw; copy.level = newuser.level; // hash the password of the copied user PasswordHasher <sqlUser> Hasher = new PasswordHasher <sqlUser>(); copy.pw = Hasher.HashPassword(copy, copy.pw); HttpContext.Session.SetString("username", copy.name); // let's save them to sql _context.usertable.Add(copy); _context.SaveChanges(); // make an id of a made user from usertable now sqlUser madeuser = _context.usertable.SingleOrDefault(a => a.email == copy.email); HttpContext.Session.SetInt32("userid", madeuser.id); return(RedirectToAction("Board")); } return(View("Index")); }
public static List <clsUser> UserList() { var objUser = new sqlUser(); return(objUser.UserList()); }
public static List <clsUser> UserListPaged(bool?status, int startPage, int pageLength, out int noOfPages, out int totalRecords) { var objUser = new sqlUser(); return(objUser.UserListPaged(status, startPage, pageLength, out noOfPages, out totalRecords)); }
public static bool UserDelete(int userId) { var objUser = new sqlUser(); return(objUser.UserDelete(userId)); }
public static bool UserAddUpdate(clsUser userInfo) { var objUser = new sqlUser(); return(objUser.UserAddUpdate(userInfo)); }
public static clsUser UserDetails(int userId) { var objUser = new sqlUser(); return(objUser.UserDetails(userId)); }
public static bool CheckUserExits(int userId, string loginId) { var objUser = new sqlUser(); return(objUser.CheckUserExits(userId, loginId)); }
public static clsUser UserLoginValidate(string loginId, string loginPwd) { var objUser = new sqlUser(); return(objUser.UserLoginValidate(loginId, loginPwd)); }