コード例 #1
0
        public ActionResult Login(UserLoginViewModel objEntity)
        {
            var objAccountRepository = new AccountRepository();
            if (ModelState.IsValid)
            {
                objEntity.UserEmail = objEntity.UserEmail.Trim();
                objEntity.Password = objEntity.Password.Trim();

                var objUserViewModel = objAccountRepository.CheckSignIn(UserFlags.UserSignIn.GetHashCode(), objEntity);
                if (objUserViewModel != null)
                {

                    SessionWrapper.UserAccount = new AccountRepository().GetAccountByUser(objUserViewModel);

                    FormsAuthentication.SetAuthCookie(Convert.ToString(objUserViewModel.UserId), false);

                    if (SessionWrapper.UserAccount.UserTypeID == UserTypes.User.GetHashCode())
                    {
                        return RedirectToAction("Dashboard", "User");
                    }
                    else if (SessionWrapper.UserAccount.UserTypeID == UserTypes.Admin.GetHashCode())
                    {
                        return RedirectToAction("Dashboard", "Admin");
                    }

                }
                else
                {
                    this.Flash("error", "We didn't recognize the username or password you entered. Please try again");

                }

            }
            return View(objEntity);
        }
コード例 #2
0
ファイル: MenuHelpers.cs プロジェクト: learningcraft2015/Blog
        public static void SetMenuByRoleMaster()
        {
            AccountRepository objAccountRepository = new AccountRepository();
            _RolesAndMenuMaster.Clear();
            List<TextMenuModel> objTextMenuList = new List<TextMenuModel>();
            objTextMenuList = objAccountRepository.GetRolesForMenus((Int16)UserAccessParentIdEnum.MasterForms.GetHashCode());
            foreach (var item in objTextMenuList)
            {
                _RolesAndMenuMaster.Add(item.RoleId, item.Menu);

            }
        }
コード例 #3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated && HttpContext.Current.User.Identity.AuthenticationType == "Forms")
            {
                if (SessionWrapper.UserAccount == null)
                {
                    var objAccountRepository = new AccountRepository();
                    if (objAccountRepository.SetAccountByUser(Convert.ToInt32(HttpContext.Current.User.Identity.Name)))
                    {

                        if (IsAdmin == StatusFlags.Deactive && SessionWrapper.UserAccount.UserTypeID == UserTypes.Admin.GetHashCode())
                        {
                            RedirectAdminLogin(filterContext);
                        }
                        if (IsUser == StatusFlags.Deactive && SessionWrapper.UserAccount.UserTypeID == UserTypes.User.GetHashCode())
                        {
                            RedirectUserLogin(filterContext);
                        }

                    }
                }
                else
                {

                    if (IsAdmin == StatusFlags.Deactive && SessionWrapper.UserAccount.UserTypeID == UserTypes.Admin.GetHashCode())
                    {
                        RedirectAdminLogin(filterContext);
                    }
                    if (IsUser == StatusFlags.Deactive && SessionWrapper.UserAccount.UserTypeID == UserTypes.User.GetHashCode())
                    {
                        RedirectUserLogin(filterContext);
                    }

                }

            }
            else
            {
                RedirectAdminLogin(filterContext);

            }

            base.OnActionExecuting(filterContext);
        }
コード例 #4
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var objController = filterContext.RouteData.Values["Controller"];
            var objAction = filterContext.RouteData.Values["Action"];
            int UserId = 0;

            if (HttpContext.Current.User.Identity.IsAuthenticated && HttpContext.Current.User.Identity.AuthenticationType == "Forms")
            {
                UserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
                if (SessionWrapper.UserAccount == null)
                {
                    var objAccountRepository = new AccountRepository();

                    if (objAccountRepository.SetAccountByUser(UserId))
                    {

                        if (ActionAccess != ActionUserAccessEnum.Default && ActionAccess != ActionUserAccessEnum.AdminOnly)
                        {
                            CheckRoleUserAccess(filterContext, new UserAccessViewModel() { Url = objController.ToString() }, SessionWrapper.UserAccount.RoleId);
                        }

                    }
                }
                else
                {

                    if (ActionAccess != ActionUserAccessEnum.Default && ActionAccess != ActionUserAccessEnum.AdminOnly)
                    {
                        CheckRoleUserAccess(filterContext, new UserAccessViewModel() { Url = objController.ToString() }, SessionWrapper.UserAccount.RoleId);
                    }
                }

            }
            else
            {
                RedirectUnAuthorizedUserLogin(filterContext);

            }
            base.OnActionExecuting(filterContext);
        }
コード例 #5
0
 public ActionResult Logout()
 {
     var objAccountRepository = new AccountRepository();
     objAccountRepository.SignOut();
     return RedirectToAction("Index", "Home");
 }
コード例 #6
0
        public int ValidateUserChangePassword(UserChangePasswordViewModel objEntity)
        {
            int result = 0;
            AccountRepository objAccountRepository = new AccountRepository();
            var objUserRepository = new UserRepository();
            var objLoginUserViewModel = objAccountRepository.GetUserDetailsforLogin(UserFlags.UserSignIn.GetHashCode(), new UserLoginViewModel() { UserEmail = objEntity.UserEmail });

            if (objLoginUserViewModel != null)
            {
                if (PasswordHelpers.Validate(objLoginUserViewModel.Password, objLoginUserViewModel.PasswordSalt, objEntity.NewPassword))
                {
                    result = ResultFlags.OldPasswordMismatch.GetHashCode();

                }
                else
                {
                    PasswordHelpers.HashedPassword objHashedPassword = PasswordHelpers.Generate(objEntity.NewPassword);
                    var objNewUserViewModel = new UserViewModel()
                    {
                        UserId = SessionWrapper.UserAccount.UserId,
                        UserEmail = SessionWrapper.UserAccount.UserEmail,
                        PasswordSalt = objHashedPassword.Salt,
                        Password = objHashedPassword.Password
                    };

                    objNewUserViewModel = objUserRepository.Update(UserFlags.UpdatePasswordByID.GetHashCode(), objNewUserViewModel);
                    result = objNewUserViewModel.Result;

                }

            }

            return result;
        }
コード例 #7
0
        public int ValidateUser(UserLoginViewModel objEntity)
        {
            int isResult = LoginResultEnum.Failure.GetHashCode();
            AccountRepository objAccountRepository = new AccountRepository();
            var objUserViewModel = objAccountRepository.GetUserDetailsforLogin(UserFlags.UserSignIn.GetHashCode(), objEntity);
            if (objUserViewModel != null)
            {
                if (objUserViewModel.RoleId == RoleUserDefinedEnum.Admin.GetHashCode())
                {

                    if (PasswordHelpers.Validate(objUserViewModel.Password, objUserViewModel.PasswordSalt, objEntity.Password))
                    {
                        isResult = AccountRepository.Login(objUserViewModel);

                    }
                }
                else
                {
                    isResult = LoginResultEnum.Unauthorized.GetHashCode();
                }

            }

            return isResult;
        }
コード例 #8
0
        public ActionResult ProfileEdit(int id, RegistrationUpdateViewModel objUpdateEntity)
        {
            var objRegistrationRepository = new RegistrationRepository();
            string fileName = string.Empty;
            string oldFileName = string.Empty;

            if (ModelState.IsValid)
            {
                #region FileUpload

                if (objUpdateEntity.UploadPhoto != null)
                {
                    fileName = Guid.NewGuid().ToString() + Path.GetExtension(objUpdateEntity.UploadPhoto.FileName);
                    oldFileName = objUpdateEntity.PhotoName;
                    objUpdateEntity.PhotoName = fileName;
                }

                #endregion
                objUpdateEntity.FirstName = objUpdateEntity.FirstName.Trim();
                objUpdateEntity.LastName = objUpdateEntity.LastName.Trim();
                objUpdateEntity.PhotoName = objUpdateEntity.PhotoName;
                objUpdateEntity.DateOfBirth = objUpdateEntity.DateOfBirth;
                objUpdateEntity.Location = objUpdateEntity.Location.Trim();
                objUpdateEntity.MobileNumber = objUpdateEntity.MobileNumber.Trim();
                objUpdateEntity.RegistrationId = id;

                var objEntity = new RegistrationViewModel()
                {
                    RegistrationId = objUpdateEntity.RegistrationId,
                    UserId = objUpdateEntity.UserId,
                    FirstName = objUpdateEntity.FirstName,
                    LastName = objUpdateEntity.LastName,
                    PhotoName = objUpdateEntity.PhotoName,

                    DateOfBirth = objUpdateEntity.DateOfBirth,
                    Gender = objUpdateEntity.Gender,

                    Location = objUpdateEntity.Location,
                    MobileNumber = objUpdateEntity.MobileNumber
                };

                objEntity = objRegistrationRepository.Update(RegistrationFlags.UpdateByID.GetHashCode(), objEntity);

                if (objEntity.Result == ResultFlags.Success.GetHashCode())
                {
                    #region FileUpload
                    //delete old file

                    //file name
                    if (objUpdateEntity.UploadPhoto != null)
                    {
                        if (!string.IsNullOrEmpty(objUpdateEntity.UploadPhoto.FileName))
                        {
                            ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), oldFileName));
                        }
                        string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), fileName);
                        // WebImage.Save()
                        objUpdateEntity.UploadPhoto.SaveAs(path);
                    }

                    #endregion

                    this.Flash("Success", "My Profile updated successfully ");

                    //reload admin profile
                    SessionWrapper.UserAccount = null;
                    AccountRepository objAccountRepository = new AccountRepository();
                    objAccountRepository.SetAccountByUser(objEntity.UserId);

                    return RedirectToAction("Dashboard", "Admin");
                }
                else if (objEntity.Result == ResultFlags.Failure.GetHashCode())
                {
                    this.Flash("Error", "My Profile failed to update");

                }
                else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode())
                {
                    this.Flash("Warning", "It already exist");

                }
            }

            return View(objUpdateEntity);
        }