示例#1
0
        //logout khoi tai khoan
        public ActionResult Logout()
        {
            FanxiAuthenticationBase _authenticationService = IoC.Resolve <FanxiAuthenticationBase>();

            _authenticationService.SigOut();
            return(RedirectToAction("LogOn"));
        }
示例#2
0
 public AccountController()
 {
     NguoidungService      = IoC.Resolve <INGUOIDUNGService>();
     _iLogSystemService    = IoC.Resolve <ILogSystemService>();
     UserDataService       = IoC.Resolve <IuserService>();
     authenticationService = IoC.Resolve <FanxiAuthenticationBase>();
 }
示例#3
0
        public static bool isAccountCorrect(string username, string password)
        {
            FanxiAuthenticationBase _authenticationService = IoC.Resolve <FanxiAuthenticationBase>();
            UserIdentity            tempId = _authenticationService.Authenticate(username, password);

            if (tempId == null)
            {
                return(false);
            }
            FanxiPrincipal _principal = new FanxiPrincipal(tempId);

            HttpContext.Current.User = _principal;
            return(true);
        }
        private bool isAccountCorrect(string username, string password)
        {
            FanxiAuthenticationBase _authenticationService = IoC.Resolve <FanxiAuthenticationBase>();
            UserIdentity            tempId = _authenticationService.Authenticate(username, password);

            if (tempId == null)
            {
                return(false);
            }
            FanxiPrincipal _principal = new FanxiPrincipal(tempId);

            HttpContext.Current.User = _principal;
            if (_Roles != null && _Roles.Length > 0)
            {
                IEnumerable <string> TempRoles = (from r in tempId.Roles where _Roles.Contains(r) select r);
                if (TempRoles == null || TempRoles.Count() == 0)
                {
                    return(false);
                }
            }
            if (_Permissions != null && _Permissions.Length > 0)
            {
                List <string> HasPermission = new List <string>();
                IList <IdentityManagement.Domain.role> roles = FX.Core.IoC.Resolve <IroleService>().Query.Where(p => tempId.Roles.Contains(p.name)).ToList();
                foreach (var r in roles)
                {
                    foreach (var per in r.Permissions)
                    {
                        if (HasPermission.Contains(per.name))
                        {
                            continue;
                        }
                        HasPermission.Add(per.name);
                    }
                }
                string[] TempPer = (from per in _Permissions where (!HasPermission.Contains(per)) select per).ToArray();
                if (TempPer != null && TempPer.Length > 0)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#5
0
        public ActionResult LogOn(LogOnModel _model, string captch)
        {
            string ip = Request.UserHostAddress == "::1"? "127.0.0.1" : Request.UserHostAddress;

            //if (!string.IsNullOrWhiteSpace(ipSecurity) && !ipSecurity.Contains(ip))
            //{
            //    _model.lblErrorMessage = "Địa chỉ của bạn không được truy cập vào trang web.";
            //    _model.Password = "";
            //    return View(_model);
            //}
            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));
            }
            FanxiAuthenticationBase _authenticationService = IoC.Resolve <FanxiAuthenticationBase>();

            try
            {
                if (_model.UserName.Trim() != null && _model.Password != null)
                {
                    if (_authenticationService.LogOn(_model.UserName.Trim(), _model.Password.Trim()) == true)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        IRBACMembershipProvider _MemberShipProvider = IoC.Resolve <IRBACMembershipProvider>();
                        user TempUser = _MemberShipProvider.GetUser(_model.UserName, true);
                        if (TempUser != null)
                        {
                            if (TempUser.FailedPasswordAttemptCount >= 5)
                            {
                                _model.lblErrorMessage = "Tài khoản đã bị khóa.";
                            }
                            else
                            {
                                TempUser.FailedPasswordAttemptCount++;
                                if (TempUser.FailedPasswordAttemptCount == 5)
                                {
                                    TempUser.IsLockedOut = true;
                                }
                                _model.lblErrorMessage = "Tài khoản hoặc mật khẩu đăng nhập không đúng";
                                _MemberShipProvider.UpdateUser(TempUser);
                            }
                            return(View(_model));
                        }
                        _model.lblErrorMessage = "Tài khoản hoặc mật khẩu đăng nhập không đúng";
                        _model.Password        = "";
                        return(View(_model));
                    }
                }
                else
                {
                    _model.Password = "";
                    return(View("LogOn", _model));
                }
            }
            catch (Exception ex)
            {
                _model.lblErrorMessage = "Tài khoản hoặc mật khẩu đăng nhập không đúng";
                _model.Password        = "";
                return(View("LogOn", _model));
            }
        }
示例#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));
            }
        }