Example #1
0
 public override void AddUsersToRoles(string[] usernames, string[] roleNames)
 {
     if (_App == null)
     {
         return;
     }
     foreach (string UN in usernames)
     {
         user mUser = UserSrv.GetByName(UN, _App.AppID);
         if (mUser != null)
         {
             string[] currentRoles = (from r in mUser.Roles where r.AppID == _App.AppID select r.name).ToArray();
             foreach (string r in roleNames)
             {
                 if (!currentRoles.Contains(r))
                 {
                     role mRole = RoleSrv.GetByName(r, _App.AppID);
                     if (mRole != null)
                     {
                         mUser.Roles.Add(mRole);
                     }
                 }
             }
         }
     }
     UserSrv.CommitChanges();
 }
Example #2
0
        public void AddUser(user mUser)
        {
            user TempUser = Mapping(mUser);

            if (TempUser == null)
            {
                mUser.ApplicationList = new List <Applications>();
                mUser.ApplicationList.Add(App);
                UserSrv.CreateNew(mUser);
            }
            else
            {
                if (!TempUser.ApplicationList.Contains(App))
                {
                    TempUser.ApplicationList.Add(App);
                }
            }
            UserSrv.CommitChanges();
        }
        //if (models.Password.IndexOfAny(UPPERCHAR) == -1)
        //       {
        //           check = true;
        //           error = "Password phải chứa ký tự hoa!";
        //       }
        //       if (models.Password.IndexOfAny(NUMBER) == -1)
        //       {
        //           check = true;
        //           error = "Password phải chứa số!";
        //       }
        //       if (models.ID != 0)
        //       {
        //           models.VaiTro_ID = currentNd.VAITRO;
        //       }
        public JsonResult UpdateUser(string _password, string _newpasswordRe, string _newpassword)
        {
            string returnedData = "NotOK";

            if (_password.Trim() != "" && _newpassword.Trim().Length >= 8 /* && _newpasswordRe.Trim().Length >= 8 && _password.IndexOfAny(SpecialChars) != -1 && _password.IndexOfAny(UPPERCHAR) != -1 && _password.IndexOfAny(NUMBER) != -1*/)
            {
                var user      = UserDataService.Getbykey(usercurent.userid);
                var pass_word = FormsAuthentication.HashPasswordForStoringInConfigFile(_password, "MD5");

                if (user.password == pass_word)
                {
                    var newpw = FormsAuthentication.HashPasswordForStoringInConfigFile(_newpassword, "MD5");
                    user.password = newpw;
                    UserDataService.Update(user);
                    UserDataService.CommitChanges();
                    returnedData            = "ok";
                    Session["MustChangePW"] = false;
                }
            }

            return(Json(returnedData, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// required implementation
        /// </summary>
        /// <param name="username">a username</param>
        /// <param name="oldPassword">original password</param>
        /// <param name="newPassword">new password</param>
        /// <returns>true or false</returns>
        public bool ChangePassword(string username, string oldPassword, string newPassword)
        {
            log.Info("ChangePassword user: "******" in Application: " + _App.AppName);

            if (_App == null)
            {
                return(false);
            }
            user TemUser = UserSrv.GetByName(username, _App.AppID);

            if (TemUser == null)
            {
                return(false);
            }
            string OldPassWordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(oldPassword, "MD5");

            if (TemUser.password != OldPassWordHash)
            {
                return(false);
            }
            string NewPassWordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(newPassword, "MD5");

            TemUser.password = NewPassWordHash;

            try
            {
                UserSrv.Update(TemUser);
                UserSrv.CommitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                log.Error("ERR in ChangePassword user: "******" in Application " + _App.AppName, ex);
                return(false);
            }
        }
Example #5
0
        public ActionResult Reset(string username)
        {
            ResetModel mm = new ResetModel();

            try
            {
                IuserService _userService    = IoC.Resolve <IuserService>();
                Company      _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                user         model           = _userService.Query.Where(u => u.GroupName.Equals(_currentCompany.id.ToString()) && u.username == username).FirstOrDefault();
                if (model != null)
                {
                    string randompass = IdentityManagement.WebProviders.RBACMembershipProvider.CreateRandomPassword(8);
                    IService.IRegisterEmailService emailSrv      = FX.Core.IoC.Resolve <IService.IRegisterEmailService>();
                    Dictionary <string, string>    subjectParams = new Dictionary <string, string>(1);
                    subjectParams.Add("$subject", "");
                    Dictionary <string, string> bodyParams = new Dictionary <string, string>(3);
                    bodyParams.Add("$password", randompass);
                    bodyParams.Add("$site", FX.Utils.UrlUtil.GetSiteUrl());
                    emailSrv.ProcessEmail("*****@*****.**", model.email, "ResetPassword", subjectParams, bodyParams);
                    model.password = GeneratorPassword.EncodePassword(randompass, model.PasswordFormat, model.PasswordSalt);//FormsAuthentication.HashPasswordForStoringInConfigFile(randompass, "MD5");
                    model.LastPasswordChangedDate = DateTime.Now;
                    _userService.Save(model);
                    _userService.CommitChanges();
                    mm.lblErrorMessage = "Kiểm tra email để lấy mật khẩu của bạn.";
                    return(View("ResetPassword", mm));
                }
                mm.lblErrorMessage = "Tài khoản không tồn tại trên hệ thống";
                return(View("ResetPassword", mm));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ResetModel model = new ResetModel();
                model.lblErrorMessage = "Tài khoản không tồn tại trên hệ thống";
                return(View("ResetPassword", mm));
            }
        }
Example #6
0
        public ActionResult LogOn(LogOnModel _model, string captch)
        {
            if (string.IsNullOrWhiteSpace(captch))
            {
                _model.lblErrorMessage = "Nhập đúng mã xác thực.";
                _model.Password        = "";
                return(View(_model));
            }
            bool cv = CaptchaController.IsValidCaptchaValue(captch);

            if (!cv)
            {
                _model.lblErrorMessage = "Nhập đúng mã xác thực.";
                _model.Password        = "";
                return(View(_model));
            }
            log.Info("Login: "******"LogOn:" + HttpContext.User.Identity.Name + ", Date:" + DateTime.Now);
                        if (!string.IsNullOrWhiteSpace(_model.ReturnUrl) && Url.IsLocalUrl(_model.ReturnUrl))
                        {
                            return(Redirect(_model.ReturnUrl));
                        }
                        return(Redirect("/"));
                    }
                    else
                    {
                        IuserService userSrv  = IoC.Resolve <IuserService>();
                        var          currComp = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                        user         TempUser = userSrv.Query.Where(u => u.username == _model.UserName && u.GroupName.Equals(currComp.id.ToString())).FirstOrDefault();
                        if (TempUser != null)
                        {
                            if (TempUser.IsLockedOut)
                            {
                                _model.lblErrorMessage = "Tài khoản đã bị khóa.";
                            }
                            else
                            {
                                if (!_model.IsThread)
                                {
                                    if (TempUser.FailedPasswordAttemptCount > 0)
                                    {
                                        TempUser.FailedPasswordAttemptCount = 0;
                                        userSrv.Save(TempUser);
                                        userSrv.CommitChanges();
                                    }
                                    _model.lblErrorMessage = Resources.Message.User_MesWrongAccOrPass;
                                    _model.Password        = "";
                                    _model.IsThread        = true;
                                    return(View(_model));
                                }
                                if (TempUser.FailedPasswordAttemptCount == 4)
                                {
                                    TempUser.IsLockedOut = true;
                                }
                                TempUser.FailedPasswordAttemptCount++;
                                _model.lblErrorMessage = Resources.Message.User_MesWrongAccOrPass;
                                userSrv.Save(TempUser);
                                userSrv.CommitChanges();
                            }
                            _model.Password = "";
                            return(View(_model));
                        }
                        _model.lblErrorMessage = Resources.Message.User_MesWrongAccOrPass;
                        _model.Password        = "";
                        return(View(_model));
                    }
                }
                else
                {
                    _model.Password = "";
                    return(View("LogOn", _model));
                }
            }
            catch (Exception ex)
            {
                log.Error("Error", ex);
                _model.lblErrorMessage = Resources.Message.User_MesWrongAccOrPass;
                _model.Password        = "";
                return(View("LogOn", _model));
            }
        }