Esempio n. 1
0
        public IActionResult Upsert(PortalLoginViewModel viewModel)
        {
            var result = new ResultViewModel()
            {
                IsSuccess = false
            };

            if (!_pr.CheckUsernameAvaiable(viewModel.Id, viewModel.Username))
            {
                ModelState.AddModelError("Username", "用户名已被使用。");
            }
            if (viewModel.RoleList == null || viewModel.RoleList.Count() == 0)
            {
                ModelState.AddModelError("RoleList", "必须选择权限。");
            }

            if (ModelState.IsValid)
            {
                bool           isNew = string.IsNullOrEmpty(viewModel.Id);
                PortalLoginDto dto;

                if (isNew)
                {
                    dto = _pr.CreatePortalLogin(viewModel.Username, viewModel.Password, viewModel.RoleList, true);
                }
                else
                {
                    // if password changed, then user need to change password when login
                    var isPasswordToChange = viewModel.IsPasswordChanged;

                    dto = _pr.UpdatePortalLogin(viewModel.Id, viewModel.Username, viewModel.Password, viewModel.RoleList, isPasswordToChange, viewModel.IsPasswordChanged, false);
                }

                if (dto != null)
                {
                    viewModel        = _mapper.Map <PortalLoginViewModel>(dto);
                    result.IsSuccess = true;
                }
            }

            var roles = _pr.GetRoles();

            ViewBag.Roles  = roles;
            ViewBag.Result = result;

            return(View("Upsert", viewModel));
        }
Esempio n. 2
0
        public IActionResult Index(LoginViewModel model)
        {
            var users = _pr.GetPortalLogins(new PortalLoginQuery()
            {
                IsValid = null
            });

            if (users.Total == 0)
            {
                if (!ModelState.IsValid)
                {
                    ViewBag.IsCreated = false;
                    return(View(model));
                }

                _pr.CreatePortalLogin(model.Username, model.Password, new string[] { "1" }, false);
                ViewBag.IsCreated = true;
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }