public ActionResult Login() { LoginArgs loginArgs = RequestArgs <LoginArgs>(); if (loginArgs == null) { return(RespondResult(false, "参数无效。")); } User user = _userManager.Verify(loginArgs.Account, loginArgs.Password); if (user == null) { return(RespondResult(false, "帐号或密码错误。")); } Domain domain = _domainManager.GetDomain(user.DomainId); AuthorizationWrapper authorizationWrapper = new AuthorizationWrapper { AuthorizationList = _userManager.GetAuthorizationListByUser(user.Id) }; UserContext userContext = new UserContext(user, domain) { RootOrganization = _domainManager.GetOrganization(domain.Id), Authorization = authorizationWrapper, RoleList = _userManager.GetRoleListByUser(user.Id), Organization = _domainManager.GetOrganization(user.OrganizationId) }; SessionContainer.SetUserContext(HttpContext, userContext); return(RespondResult()); }
public ActionResult Login() { LoginArgs args = RequestArgs <LoginArgs>(); if (args == null) { return(RespondResult(false, "参数无效。")); } UserEntity user = _userManager.Verify(args.Account, args.Password); if (user == null) { return(RespondResult(false, "帐号或密码错误。")); } UserContext userContext = new UserContext(user); SessionContainer.SetUserContext(this.HttpContext, userContext); this.UserContext = userContext; this.DomainContext = _domainPool.GetDomainContext(UserContext.User.Domain); //操作日志 _operatedLogManager.Create(new OperatedLogEntity() { Domain = DomainContext.Domain.Id, AppId = DomainContext.AppId, User = userContext.User.Id, IP = Request.UserHostAddress, Module = EnumModule.System, Description = "用户登陆" }); return(RespondResult()); }
public ActionResult Register() { UserRegisterArgs userRegisterArgs = RequestArgs <UserRegisterArgs>(); if (userRegisterArgs == null) { return(RespondResult(false, "参数无效。")); } if (!HttpContext.Session.TryGetValue("ValidateCode", out var value)) { return(RespondResult(false, "验证码无效。")); } if (Encoding.UTF8.GetString(value) != userRegisterArgs.ValidateCode) { return(RespondResult(false, "验证码无效。")); } UserRegisterResult userRegisterResult = _userManager.Register(userRegisterArgs); if (userRegisterResult.Result == UserRegisterResultEnum.Success) { UserContext userContext = new UserContext(userRegisterResult.User, userRegisterResult.Domain) { RootOrganization = UserController._domainManager.GetOrganization(userRegisterResult.Domain.Id), Authorization = new AuthorizationWrapper(), Organization = UserController._domainManager.GetOrganization(userRegisterResult.User.OrganizationId) }; SessionContainer.SetUserContext(HttpContext, userContext); return(RespondResult()); } ApiResult apiResult = new ApiResult { Success = false }; switch (userRegisterResult.Result) { case UserRegisterResultEnum.Unknow: apiResult.Message = "未知错误。"; break; case UserRegisterResultEnum.AccountInUse: apiResult.Message = "帐户被占用,请尝试其它帐户名称。"; break; case UserRegisterResultEnum.UserInfoInvalid: apiResult.Message = "帐户被占用,用户信息无效。"; break; } return(RespondResult(apiResult)); }
public ActionResult Login() { ParametersContainer args = RequestArgs <ParametersContainer>(); if (args == null) { return(FailedResult("参数无效。")); } NormalResult <UserContext> result = _userContextManager.Login(args.GetValue("Account"), args.GetValue("Password")); if (result.Successful) { ShellUserContext userContext = Mapper.Map <ShellUserContext>(result.Data); userContext.User = UserManager.Instance.GetUser(userContext.UserId); SessionContainer.SetUserContext(HttpContext, userContext); return(DataResult(result.Data)); } else { return(FailedResult(result.Message)); } }
public ActionResult Register() { UserRegisterArgs args = RequestArgs <UserRegisterArgs>(); if (args == null) { return(RespondResult(false, "参数无效。")); } string mobileValidateCode = _cachingService.Get(args.MobilePhone); if (String.IsNullOrEmpty(mobileValidateCode)) { return(RespondResult(false, "手机验证码已过期,请重新获取。")); } if (mobileValidateCode != args.MobilePhoneValidateCode) { return(RespondResult(false, "手机验证码无效。")); } //if (Session["ValidateCode"] == null || // Session["ValidateCode"].ToString() != args.ValidateCode) //{ // return RespondResult(false, "验证码无效。"); //} UserRegisterResult result = _userManager.Register(args); if (result.Result == UserRegisterResultEnum.Success) { //UserContext userContext = new UserContext(result.User, result.Domain); UserContext userContext = new UserContext(result.User); SessionContainer.SetUserContext(this.HttpContext, userContext); return(RespondResult()); } else { ApiResult apiResult = new ApiResult() { Success = false }; switch (result.Result) { case UserRegisterResultEnum.Unknow: apiResult.Message = "未知错误。"; break; case UserRegisterResultEnum.AccountInUse: apiResult.Message = "帐户被占用,请尝试其它帐户名称。"; break; case UserRegisterResultEnum.UserInfoInvalid: apiResult.Message = "帐户被占用,用户信息无效。"; break; default: Debug.Assert(false, "未捕获的状态。"); break; } return(RespondResult(apiResult)); } }