Ejemplo n.º 1
0
        public bool CreateNewPassword(ResetPasswordViewModel user)
        {
            byte[] passwordHash, passwordSalt;
            var    userlogin = Login(user.Email, user.OldPassword);

            if (userlogin == null)
            {
                return(false);
            }
            if (!VerifyPassword(user.OldPassword, userlogin.PasswordHash, userlogin.PasswordSalt))
            {
                return(false);
            }
            CreatePasswordHash(user.Password, out passwordHash, out passwordSalt);
            var u = new CreateNewPasswordModel
            {
                Email        = user.Email,
                PasswordHash = passwordHash,
                PasswordSalt = passwordSalt
                               //Password = user.Password,
                               //OldPassword = user.OldPassword
            };
            bool isRegister = _authProcessor.CreateNewPassword(u);

            if (isRegister)
            {
                return(true);
            }
            throw new UserNotCreatedException("Unable to change password, Please insert vailid email and password");
        }
Ejemplo n.º 2
0
 public bool CreateNewPassword(CreateNewPasswordModel user)
 {
     using (var connection = new SqlConnection(connectionString))
     {
         try
         {
             SqlParameter[] parameters = new SqlParameter[] {
                 new SqlParameter("@Email", user.Email),
                 new SqlParameter("@passwordSalt", user.PasswordSalt),
                 new SqlParameter("@passwordHash", user.PasswordHash),
                 //new SqlParameter("@Password",user.Password),
                 //new SqlParameter("@OldPassword",user.OldPassword)
             };
             var result =
                 SqlHelper.ExecuteNonQuery
                 (
                     connection,
                     CommandType.StoredProcedure,
                     "usp_CreateNewPassword",
                     parameters
                 );
             if (result > 0)
             {
                 return(true);
             }
         }
         finally
         {
             SqlHelper.CloseConnection(connection);
         }
     }
     throw new UserNotCreatedException("Unable to change password, either email id or password is not vailid");
 }
Ejemplo n.º 3
0
        public ApiHeader ActiveUser(ApiHeader apiHeader, CreateNewPasswordModel model)
        {
            var       url    = ApiUrl.Default.RootApi + string.Format(ApiUrl.Default.ActiveClinic, model.Hash, model.Email);
            var       data   = Restful.Get(url, apiHeader);
            ApiHeader header = data.Get <ApiHeader>();

            CreatePassword(header, model);
            return(header);
        }
        public bool CreateNewPassword(ResetPasswordViewModel user)
        {
            var u = new CreateNewPasswordModel
            {
                Password    = user.Password,
                Email       = user.Email,
                OldPassword = user.OldPassword
            };
            bool isRegister = _authProcessor.CreateNewPassword(u);

            if (isRegister)
            {
                return(true);
            }
            throw new UserNotCreatedException("Unable to change password, Please insert vailid email and password");
        }
Ejemplo n.º 5
0
        private void CreatePassword(ApiHeader apiHeader, CreateNewPasswordModel model)
        {
            var url = ApiUrl.Default.RootApi + ApiUrl.Default.ChangePassword;

            Restful.Post(url, apiHeader, model);
        }
Ejemplo n.º 6
0
        public ActionResult CreatePassword(CreateNewPasswordModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                model.OldPassword = "";
                ApiHeader apiHeader = _clinicService.ActiveUser(BaseApiHeader, model);

                apiHeader.Hospitals = apiHeader.Hospitals?.Where(x => x.Status == 1).ToList();
                var oldCookie = HttpContext.Request.Cookies[CookieConstant.ApiHeader];
                if (oldCookie != null)
                {
                    oldCookie.Expires = DateTime.Now.AddDays(-1);
                    HttpContext.Response.Cookies.Add(oldCookie);
                }

                var oldCookieHospital = HttpContext.Request.Cookies[CookieConstant.HospitalSelected];
                if (oldCookieHospital != null)
                {
                    oldCookieHospital.Expires = DateTime.Now.AddDays(-1);
                    HttpContext.Response.Cookies.Add(oldCookieHospital);
                }

                if (apiHeader.Hospitals != null && apiHeader.Hospitals.Count > 0)
                {
                    var cookieHospital = new HttpCookie(CookieConstant.HospitalSelected)
                    {
                        Value   = JsonConvert.SerializeObject(apiHeader.Hospitals[0]),
                        Expires = Utils.UnixTimeStampToDateTime(apiHeader.SessionExpired)
                    };
                    HttpContext.Response.Cookies.Add(cookieHospital);
                    apiHeader.HospitalSelected = apiHeader.Hospitals[0].HospitalId;
                    apiHeader.HospitalSubType  = apiHeader.Hospitals[0].SubType;
                    apiHeader.HospitalRoles    = apiHeader.Hospitals[0].Roles;
                    apiHeader.HospitalName     = apiHeader.Hospitals[0].Name;
                }
                //if (apiHeader.User != null)
                //    apiHeader.User.DoctorInfos = null;
                var cookie = new HttpCookie(CookieConstant.ApiHeader)
                {
                    Value   = JsonConvert.SerializeObject(apiHeader),
                    Expires = Utils.UnixTimeStampToDateTime(apiHeader.SessionExpired)
                };
                HttpContext.Response.Cookies.Add(cookie);
                HttpContext.Response.Cookies.Add(new HttpCookie("timezone")
                {
                    Value   = model.TimeZone,
                    Expires = Utils.UnixTimeStampToDateTime(apiHeader.SessionExpired)
                });
                if (apiHeader.Hospitals != null && apiHeader.Hospitals.Count == 0)
                {
                    RemoveCookie();
                }
                return(RedirectToAction("Index", "Appointment"));
                //model.OldPassword = "";
                //var apiHeader = new ApiHeader();
                //apiHeader.UserId = result[1].Value.ToString();
                //apiHeader.SessionId = result[0].Value.ToString();
                //_clinicService.CreatePassword(apiHeader, model);
                //ViewBag.email = model.Email;
                //ViewBag.password = model.Password;
                //ViewBag.createPass = "******";
                //return View();
            }
            catch (ApiException)
            {
                //TempData[GlobalConstant.ErrorTemp] = ex.Message;
                // ignored
                return(RedirectToAction("CreatePasswordError"));
            }
        }