// GET: mLogins public IActionResult Index() { mLogin mLogin = null; return(View(mLogin)); //return View(await _context.MLogins.ToListAsync()); }
public async Task <IActionResult> Edit(string id, [Bind("UserID,Password,Name,Type,Phone,EmailID")] mLogin mLogin) { if (id != mLogin.UserID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mLogin); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!mLoginExists(mLogin.UserID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(mLogin)); }
public async Task <IActionResult> Create([Bind("UserID,Password,Name,Type,Phone,EmailID")] mLogin mLogin) { if (ModelState.IsValid) { _context.Add(mLogin); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mLogin)); }
public IActionResult Index(mLogin mLogin) { try { if (ModelState.IsValid) { mLogin mLogins = null; mLogins = _context.MLogins.Where(x => x.UserID.ToUpper() == mLogin.UserID.ToUpper() && x.Password == mLogin.Password).FirstOrDefault(); //Check the user name and password //Here can be implemented checking logic from the database ClaimsIdentity identity = null; bool isAuthenticated = false; if (mLogins != null && (mLogins.Name.Trim() != null && mLogins.Name.Trim() != "")) { //Create the identity for the user identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, mLogins.UserID.Trim()), new Claim(ClaimTypes.Role, mLogins.Type.Trim()), new Claim(ClaimTypes.Email, mLogins.EmailID.Trim()), new Claim(ClaimTypes.GivenName, mLogins.Name.Trim()), new Claim(ClaimTypes.MobilePhone, mLogins.Phone.Trim()) }, CookieAuthenticationDefaults.AuthenticationScheme); HttpContext.Session.SetString("login", "true"); HttpContext.Session.SetString("UserName", mLogins.Name.Trim()); isAuthenticated = true; } if (isAuthenticated) { var principal = new ClaimsPrincipal(identity); var login = HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); return(RedirectToAction("DashBoard", "Home")); } else { ModelState.AddModelError(string.Empty, "Invalid User ID Or Password"); } } return(View()); } catch (Exception ex) { ModelState.AddModelError(string.Empty, "Some Problem occur while sending request please report it." + ex.Message.ToString()); return(View()); } }
public ActionResult Login(mLogin login) { if (login != null && login.User != null && login.Password != null) { if (login.User.Equals("admin") || login.Password.Equals("admin")) { login.setLoginOk(); return(RedirectToAction("Index")); } } return(View()); }
public ActionResult Index([Bind(Include = "username,password")] mLogin mLog) { try { if (!ModelState.IsValid) { System.Collections.Generic.IEnumerable <System.Exception> errors = ModelState.SelectMany(x => x.Value.Errors.Select(z => z.Exception)); ModelState.AddModelError("authenticationError", "User name or Password is wrong. Try it again"); return(View(mLog)); } bool userLoging = ClsLogin.IsValidUser(mLog.username, mLog.password); if (userLoging == true) { Web.HttpContext.Current.Session["Login"] = true; FormsAuthentication.SetAuthCookie(ClsLogin.StrUserName, false); Web.HttpContext.Current.Session["UserName"] = ClsLogin.StrUserName; Web.HttpContext.Current.Session["UserType"] = ClsLogin.StrUserType; Web.HttpContext.Current.Session["UserEmail"] = ClsLogin.StrUserEmail; Web.HttpContext.Current.Session["UserPhone"] = ClsLogin.StrUserPhone; return(RedirectToAction("Home", "Home")); } else { ModelState.AddModelError("authenticationError", "User name or Password is wrong. Try it again"); return(View()); } } catch (System.Exception) { throw; } }
//private DbCxAdminDashBoard DbCxADB = new DbCxAdminDashBoard(); public static bool IsValidUser(string StrUserId, string StrPassword) { try { using (DbCxSnat DbCxADB = new DbCxSnat()) { mLogin User = DbCxADB.MLogins.Where(b => b.username == StrUserId & b.password == StrPassword).FirstOrDefault(); if (User != null) { switch (User.employee) { case "E": var vEmployeeDetails = DbCxADB.mEmployeeDetails.Where(emp => emp.employeeno == User.employeeno).FirstOrDefault(); if (vEmployeeDetails != null) { StrUserName = ClsUtility.StringDbNull(vEmployeeDetails.name); StrUserType = ClsUtility.StringDbNull(User.usertype); StrUserEmail = ClsUtility.StringDbNull(vEmployeeDetails.email); StrUserPhone = ClsUtility.StringDbNull(vEmployeeDetails.contactno1); } break; case "M": var vMemberDetails = DbCxADB.mMembers.Where(emp => emp.nationalid == User.Memnationalid).FirstOrDefault(); if (vMemberDetails != null) { StrUserName = ClsUtility.StringDbNull(vMemberDetails.membername); StrUserType = ClsUtility.StringDbNull(User.usertype); StrUserEmail = ClsUtility.StringDbNull(vMemberDetails.email); StrUserPhone = ClsUtility.StringDbNull(vMemberDetails.contactno1); } break; case "A": StrUserName = "******"; StrUserType = ClsUtility.StringDbNull(User.usertype); StrUserEmail = ClsUtility.StringDbNull(User.emailid); StrUserPhone = ClsUtility.StringDbNull(User.contactno); break; default: StrUserName = ClsUtility.StringDbNull(User.username); StrUserType = ClsUtility.StringDbNull(User.usertype); StrUserEmail = ClsUtility.StringDbNull(User.emailid); StrUserPhone = ClsUtility.StringDbNull(User.contactno); break; } StrUserName = StrUserName == "" ? ClsUtility.StringDbNull(User.username) : StrUserName; StrUserType = StrUserType == "" ? ClsUtility.StringDbNull(User.usertype) : StrUserType; StrUserEmail = StrUserEmail == "" ? ClsUtility.StringDbNull(User.emailid) : StrUserEmail; StrUserPhone = StrUserPhone == "" ? ClsUtility.StringDbNull(User.contactno) : StrUserPhone; return(true); } else { return(false); } } } catch (System.Exception) { throw; } }
private void pressRegisterMethod(mLogin sender, EventArgs e) { Frm.frmRegister frm = new frmRegister(); frm.Show(); }