Beispiel #1
0
        public ActionResult Login(Login_tbl login_Tbl)
        {
            login_Tbl.Password = UrlSecurityManager.Encrypt(login_Tbl.Password, ConfigurationManager.AppSettings["SecurityKey"]);
            var Result = _loginService.UserLogin(login_Tbl);

            if (Result == null)
            {
                //TempData["Success"] = "False";
                //TempData["Message"] = "You are not a valid user...Please Register..!!";
                ViewBag.Message = "You are not a valid user...Please Register..!!";
                return(View());
            }
            else if (Result.RoleID == 4)
            {
                FormsAuthentication.SetAuthCookie(Result.UserName, false);
                Session["AdminLoginID"] = Result.ID;
                Session["RoleID"]       = Result.RoleID;
                Session["AdminName"]    = Result.FirstName + " " + Result.LastName;
                var res       = _UseradminService.GetUserList().ToList();
                var viewModel = AutoMapper.Mapper.Map <List <Login_tbl>, List <Login_tbl> >(res);
                Session["UserList"] = viewModel;
                //  Session["UserLoginID"] = viewModel;
                return(RedirectToAction("Index", "Home"));
            }
            else if (Result.RoleID == 5)
            {
                FormsAuthentication.SetAuthCookie(Result.UserName, false);
                Session["UserLoginID"] = Result.ID;
                Session["RoleID"]      = Result.RoleID;
                Session["UserNamee"]   = Result.FirstName + " " + Result.LastName;
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.Message = "You are not a valid user...Please Register..!!";
                return(View());
            }
            // return View();
        }
 public ActionResult Register(RegistrationVM p_RegistrationVM)
 {
     if (p_RegistrationVM.ID != 0)
     {
         var res = _UseradminService.SaveEditUserDetails(new Login_tbl
         {
             ID          = p_RegistrationVM.ID,
             FirstName   = p_RegistrationVM.FirstName,
             LastName    = p_RegistrationVM.LastName,
             UserName    = p_RegistrationVM.Email,
             Password    = UrlSecurityManager.Encrypt(p_RegistrationVM.Password, ConfigurationManager.AppSettings["SecurityKey"]), //p_RegistrationVM.Password,
             CustomerId  = p_RegistrationVM.CustomerId,
             MobileNo    = p_RegistrationVM.MobileNo,
             RoleID      = 5,
             CreatedDate = DateTime.Now,
             CreatedBy   = Convert.ToDecimal(Session["RoleID"]),
             IsDeleted   = false,
             AdminId     = Convert.ToInt32(Session["AdminLoginID"])
         });
         if (res.Item1 == true)
         {
             //bool success = SendEmail(p_RegistrationVM.Email, p_RegistrationVM.Password, p_RegistrationVM.FirstName);
             //if (success)
             //{
             return(Json(new { result = true, Message = "User Update Successful", url = "/Admin/User" }));
             //}
             //else
             //{
             //    return Json(new { result = true, Message = "User Registration Successful but Email not sent", url = "/Admin/User" });
             //}
         }
         else
         {
             //if (res.Item2 == true)
             //{
             //    return Json(new { result = false, Message = "Email already Exists.", url = "/Admin/User/Register" });
             //}
             //else
             //{
             return(Json(new { result = false, Message = "something went wrong,please try again.", url = "/Admin/User/Register" }));
             //}
         }
     }
     else
     {
         var res = _UseradminService.RegisterUser(new Login_tbl
         {
             FirstName   = p_RegistrationVM.FirstName,
             LastName    = p_RegistrationVM.LastName,
             UserName    = p_RegistrationVM.Email,
             Password    = UrlSecurityManager.Encrypt(p_RegistrationVM.Password, ConfigurationManager.AppSettings["SecurityKey"]), //p_RegistrationVM.Password,
             CustomerId  = p_RegistrationVM.CustomerId,
             MobileNo    = p_RegistrationVM.MobileNo,
             RoleID      = 5,
             CreatedDate = DateTime.Now,
             CreatedBy   = Convert.ToDecimal(Session["RoleID"]),
             IsDeleted   = false,
             AdminId     = Convert.ToInt32(Session["AdminLoginID"])
         });
         if (res.Item1 == true)
         {
             bool success = SendEmail(p_RegistrationVM.Email, p_RegistrationVM.Password, p_RegistrationVM.FirstName);
             if (success)
             {
                 return(Json(new { result = true, Message = "User Registration Successful and Email Sent", url = "/Admin/User" }));
             }
             else
             {
                 return(Json(new { result = true, Message = "User Registration Successful but Email not sent", url = "/Admin/User" }));
             }
         }
         else
         {
             if (res.Item2 == true)
             {
                 return(Json(new { result = false, Message = "Email already Exists.", url = "/Admin/User/Register" }));
             }
             else
             {
                 return(Json(new { result = false, Message = "something went wrong,please try again.", url = "/Admin/User/Register" }));
             }
         }
     }
 }
Beispiel #3
0
 public ActionResult ChangePassword(ChangePasswordVM ChangePasswordVM)
 {
     if (ChangePasswordVM.NewPassword.Equals(ChangePasswordVM.ConfirmPassword))
     {
         var Result = _loginService.ChangePassword(Session["UnEncryptedEmail"].ToString(), UrlSecurityManager.Encrypt(ChangePasswordVM.NewPassword, ConfigurationManager.AppSettings["SecurityKey"]));
         if (Result)
         {
             return(Json(new { Message = "Change Password Successful", url = "/Login/Login" }));
         }
         else
         {
             return(Json(new { Message = "Change Password UnSuccessful", url = "/Login/Login" }));
         }
     }
     else
     {
         return(Json(new { Message = "New Password and Confirm Password do not match.Please try again", url = "/Login/Login" }));
     }
 }
Beispiel #4
0
        public ActionResult ForgotPassword(string Email)
        {
            Login_tbl Login_tbl = _loginService.ForgotPassword(Email);

            if (Login_tbl != null)
            {
                var EmailInfo = _loginService.AddEmailInfo(Login_tbl.ID);
                var smtp      = new SmtpClient
                {
                    Host                  = ConfigurationManager.AppSettings["Host"],
                    Port                  = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]),
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(ConfigurationManager.AppSettings["AdminId"], ConfigurationManager.AppSettings["AdminPassword"])
                };
                using (var message = new MailMessage(new MailAddress(ConfigurationManager.AppSettings["AdminId"], "Admin"), new MailAddress(Email, "user"))
                {
                    Subject = "Reset Password",
                    Body = "Hello " + Login_tbl.FirstName + ",<br/><br/>Welcome to Online Training Portal. We received a request to reset your password.Please <a href=" + ConfigurationManager.AppSettings["ChangePasswordUrl"] + "/" + UrlSecurityManager.Encrypt(EmailInfo.ID.ToString(), ConfigurationManager.AppSettings["SecurityKey"]) + ">Click Here</a> to reset Password<br/><br/>This link is only valid for 30 minutes. <br/><br/><br/>Regards,<br/>Admin"
                })
                {
                    message.IsBodyHtml = true;
                    smtp.Send(message);
                }
                TempData["Success"] = "True";
                TempData["Message"] = "please check your email to change password";
                return(RedirectToAction("Login"));
            }
            else
            {
                TempData["Success"] = "False";
                TempData["Message"] = "Email does not exist.Please contact Admin for registration";
                return(RedirectToAction("Login"));
            }
        }