示例#1
0
        public IActionResult ResetPassword(ForgotPasswordModel userModel)
        {
            long id;

            if (userModel.ConfirmPassword != userModel.Password)
            {
                TempData[Enums.NotifyType.Error.GetDescription()] = "Password and Confirm Password must be same.";
                return(View("ResetPassword"));
            }

            TblUser model = _service.GetById(userModel.UserId);

            model.Password = EncryptionDecryption.GetEncrypt(userModel.Password);
            using (PolyFilmsContext contex = BaseContext.GetDbContext())
            {
                model.Token = null;
                model.TokenExpiryDateTime = null;
                contex.TblUser.Update(model);
                id = contex.SaveChanges();
            }
            if (id > 0)
            {
                TempData[Enums.NotifyType.Success.GetDescription()] = "Password reset successful.";
                return(View("Login", new LoginModel()));
            }
            TempData[Enums.NotifyType.Error.GetDescription()] = "Something went wrong. Please try again later.";
            return(View("ResetPassword"));
        }
示例#2
0
        public ActionResult ForgotPassword(string emailValue, int Type)
        {
            try
            {
                using (var ctx = new LicenseApplicationContext())
                {
                    string link = string.Empty;
                    var    user = ctx.Users.Where(a => a.Email == emailValue).FirstOrDefault();
                    if (user != null && user.UsersID > 0)
                    {
                        string resetPasswordParameter        = string.Format("{0}#{1}#{2}", SystemEnum.RoleType.User.GetHashCode(), user.UsersID, DateTime.Now.AddMinutes(ProjectConfiguration.ResetPasswordExpireTime).ToString(ProjectConfiguration.EmailDateTimeFormat));
                        string encryptResetPasswordParameter = EncryptionDecryption.GetEncrypt(resetPasswordParameter);
                        string encryptResetPasswordUrl       = string.Format("{0}?q={1}", ProjectConfiguration.SiteUrlBase + TradingLicense.Web.Pages.Controllers.Account + "/" + Actions.ResetPassword, encryptResetPasswordParameter);

                        if (UserMail.SendForgotPassword(user.Email, user.Username, encryptResetPasswordUrl))
                        {
                            return(Json(new object[] { Convert.ToInt32(MessageType.success), MessageType.success.ToString(), Messages.Mailsend }, JsonRequestBehavior.AllowGet));
                        }
                        else
                        {
                            return(Json(new object[] { Convert.ToInt32(MessageType.danger), MessageType.danger.ToString(), Messages.ContactToAdmin }, JsonRequestBehavior.AllowGet));
                        }
                    }
                    else
                    {
                        return(Json(new object[] { Convert.ToInt32(MessageType.danger), MessageType.danger.ToString(), Messages.InvalidEmail }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                // ErrorLogHelper.Log(ex);
                return(Json(new object[] { Convert.ToInt32(MessageType.danger), MessageType.danger.ToString(), Messages.ContactToAdmin }, JsonRequestBehavior.AllowGet));
            }
        }
示例#3
0
        public ActionResult ResetPassword(ResetPasswordModel resetPasswordModel)
        {
            using (var ctx = new LicenseApplicationContext())
            {
                if (resetPasswordModel.NewPassword != resetPasswordModel.ConfirmPassword)
                {
                    ViewBag.openPopup = CommonHelper.ShowAlertMessageToastr(MessageType.danger.ToString(), Messages.ResetPasswordMatch);
                    return(View(Actions.ResetPassword, resetPasswordModel));
                }

                if (resetPasswordModel.RoleTypeId == SystemEnum.RoleType.User.GetHashCode())
                {
                    var user = ctx.Users.Where(u => u.UsersID == resetPasswordModel.Id).FirstOrDefault();
                    if (user != null && user.UsersID > 0)
                    {
                        user.Password = EncryptionDecryption.GetEncrypt(resetPasswordModel.NewPassword);
                        ctx.Users.AddOrUpdate(user);
                        ctx.SaveChanges();

                        UsersModel usermodel = new UsersModel();
                        usermodel             = Mapper.Map <UsersModel>(user);
                        ProjectSession.UserID = user.UsersID;
                        ProjectSession.User   = usermodel;

                        FormsAuthentication.SetAuthCookie(ProjectSession.UserName, false);
                        return(RedirectToAction(Actions.Individual, Pages.Controllers.Master));
                    }
                    else
                    {
                        ViewBag.openPopup = CommonHelper.ShowAlertMessageToastr(MessageType.danger.ToString(), Messages.UrlNotExist);
                        return(View(Actions.ResetPassword, resetPasswordModel));
                    }
                }
                else
                {
                    ViewBag.openPopup = CommonHelper.ShowAlertMessageToastr(MessageType.danger.ToString(), Messages.ResetPasswordRequest);
                    return(View(Actions.ResetPassword, resetPasswordModel));
                }
            }
        }
示例#4
0
        public async Task <IActionResult> Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                TblUser logedInUser = _service.ValidateUser(model.UserName, EncryptionDecryption.GetEncrypt(model.Password));

                if (logedInUser == null)
                {
                    TempData[Enums.NotifyType.Error.GetDescription()] = "Invalid Login Credentials.";
                    return(View(model));
                }

                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Name, logedInUser.UserId.ToString())
                };

                var userIdentity = new ClaimsIdentity(claims, "login");

                ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);

                await HttpContext.SignInAsync(principal, new AuthenticationProperties
                {
                    IsPersistent = model.RememberMe,
                    ExpiresUtc   = DateTime.UtcNow.AddMinutes(120),
                });

                SessionHelper.UserId                = logedInUser.UserId;
                SessionHelper.RoleId                = logedInUser.RoleId ?? 0;
                SessionHelper.WelcomeUser           = logedInUser.Name;
                SessionHelper.IsSuperAdmin          = logedInUser.IsSuperAdmin ? 1 : 0;
                SessionHelper.UserAccessPermissions = CustomRepository.UserAccessPermissions(SessionHelper.RoleId, logedInUser.IsSuperAdmin);
                CommonHelper.UserId = logedInUser.UserId;
                return(RedirectToAction("Index", "Home"));
            }
            return(View(model));
        }
示例#5
0
        public IActionResult KendoSave([DataSourceRequest] DataSourceRequest request, UserModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
            }

            string message = string.Empty;

            try
            {
                if (model.UserId > 0)
                {
                    model.Password = EncryptionDecryption.GetEncrypt(model.Password);
                    _service.Update(model);
                }
                else
                {
                    model.Password = EncryptionDecryption.GetEncrypt(model.Password);
                    model.UserId   = _service.Insert(model);
                }
            }
            catch (Exception ex)
            {
                message = CommonHelper.GetErrorMessage(ex);
            }


            ModelState.Clear();
            if (!string.IsNullOrEmpty(message))
            {
                ModelState.AddModelError("Name", message);
            }

            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
示例#6
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            try
            {
                _10SoftDental.BAL.Common.CommonBAL _common = new _10SoftDental.BAL.Common.CommonBAL();
                DataSet _dataSet = new DataSet();
                Helper.EncryptionDecryption encryption = new EncryptionDecryption();
                _dataSet = _common.ValidateUser(context.UserName, encryption.GetEncrypt(context.Password));
                if (_dataSet != null)
                {
                    var Identity = new ClaimsIdentity(context.Options.AuthenticationType);
                    Identity.AddClaim(new Claim("UserID", context.Password));
                    var props = new AuthenticationProperties(new Dictionary <string, string>
                    {
                        {
                            "UserEmail", _dataSet.Tables[0].Rows[0]["UserEmail"].ToString()
                        },
                        {
                            "IsActive", _dataSet.Tables[0].Rows[0]["IsActive"].ToString()
                        },

                        {
                            "UserName", _dataSet.Tables[0].Rows[0]["UserName"].ToString()
                        },
                        {
                            "BranchIdRef", _dataSet.Tables[0].Rows[0]["BranchIdRef"].ToString()
                        },
                        {
                            "UserId", _dataSet.Tables[0].Rows[0]["UserId"].ToString()
                        },
                        {
                            "ClinicId", _dataSet.Tables[0].Rows[0]["ClinicId"].ToString()
                        },
                        {
                            "IsSystemAdmin", _dataSet.Tables[0].Rows[0]["IsSystemAdmin"].ToString()
                        },
                        {
                            "UserEmployeePatientId", _dataSet.Tables[0].Rows[0]["UserEmployeePatientId"].ToString()
                        },
                        {
                            "JobGroupForeignName", _dataSet.Tables[0].Rows[0]["JobGroupForeignName"].ToString()
                        },
                        {
                            "JobGroupLocalName", _dataSet.Tables[0].Rows[0]["JobGroupLocalName"].ToString()
                        },
                        {
                            "JobGroupIdRef", _dataSet.Tables[0].Rows[0]["JobGroupIdRef"].ToString()
                        },
                        {
                            "UserType", _dataSet.Tables[0].Rows[0]["UserType"].ToString()
                        },
                        {
                            "ClinicIdRef", _dataSet.Tables[0].Rows[0]["ClinicIdRef"].ToString()
                        }
                    });
                    AuthenticationTicket ticket = new AuthenticationTicket(Identity, props);
                    context.Validated(Identity);
                    context.Validated(ticket);
                }
                else
                {
                    context.SetError("User Identification Number Not Valid");
                    return;
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }