Exemplo n.º 1
0
 private void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         var user = UsersinfoRepository.ValidateUser(new NPD.DAL.EntityFramework.UsersInfo()
         {
             Email = txtUserName.Text, Password = txtPassword.Text
         });
         if (user == null)
         {
             MessageBox.Show("Invalid username or password", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         var loggedUser = new LoggedUser()
         {
             Id       = user.Id,
             Name     = user.Name,
             RoleId   = Convert.ToInt32(user.RoleId),
             UserName = user.Email,
             Password = txtPassword.Text
         };
         AuthenticatedDetails.LoggedUser = loggedUser;
         frmMaster obj = new frmMaster();
         obj.Show();
         this.Hide();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to login", "Error !!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 2
0
 public ActionResult Index(LoginDTO model)
 {
     try
     {
         var user = UsersinfoRepository.ValidateUser(new NPD.DAL.EntityFramework.UsersInfo()
         {
             Email = model.UserName, Password = model.Password
         });
         if (user == null)
         {
             ViewBag.Message = "Invalid username or password";
             ViewBag.IsError = true;
             return(View());
         }
         FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
         FormsAuthentication.RedirectFromLoginPage(model.UserName, model.RememberMe);
         var loggedUser = new LoggedUser()
         {
             Id       = user.Id,
             Name     = user.Name,
             RoleId   = Convert.ToInt32(user.RoleId),
             UserName = user.Email,
             Password = model.Password
         };
         Session["LoggedUser"] = loggedUser;
         return(RedirectToAction("Index", "Job"));
     }
     catch (Exception ex)
     {
         ViewBag.Message = "Failed to validate details";
         ViewBag.IsError = true;
     }
     return(View());
 }