public UserRegisterResult Register(UserRegisterArgs args) { UserRegisterResult userRegisterResult = new UserRegisterResult(); if (args == null) { userRegisterResult.Result = UserRegisterResultEnum.UserInfoInvalid; return(userRegisterResult); } object lockObj = this._lockObj; lock (lockObj) { List <CommandParameter> list = new List <CommandParameter>(); list.Add(new CommandParameter("@account", args.Account)); if (int.Parse(this._dataBase.ExecuteScalar("SELECT Count(Id) FROM [User] WHERE [Account] = @account", list).ToString()) > 0) { userRegisterResult.Result = UserRegisterResultEnum.AccountInUse; return(userRegisterResult); } Domain domain = new Domain(); UserManager._domainManager.Create(domain); Organization organization = new Organization { Id = domain.Id, Domain = domain.Id, Name = args.DomainName }; UserManager._domainManager.CreateOrganization(organization); User user = new User { Account = args.Account, Password = args.Password, Name = args.Name, Telphone = args.Telphone, Email = args.Email, DomainId = domain.Id, OrganizationId = organization.Id, Notify = true }; this._dataBase.Insert(user); Dictionary <string, object> dictionary = new Dictionary <string, object> { { "Domain", domain.Id } }; WorkType workType = this._dataBase.Select <WorkType>(dictionary)[0]; UserWorkType userWorkType = new UserWorkType { Domain = domain.Id, User = user.Id, WorkType = workType.Id }; this._dataBase.Insert(userWorkType); userRegisterResult.User = user; userRegisterResult.Domain = domain; } userRegisterResult.Result = UserRegisterResultEnum.Success; return(userRegisterResult); }
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 UserRegisterResult Register(UserRegisterArgs args) { UserRegisterResult result = new UserRegisterResult(); if (args == null) { Debug.Assert(false, "用户信息无效"); result.Result = UserRegisterResultEnum.UserInfoInvalid; return(result); } lock (_lockUserObj) { List <CommandParameter> parameterList = new List <CommandParameter>(); parameterList.Add(new CommandParameter("@account", args.Account)); int accountCount = int.Parse(_dataBase.ExecuteScalar( "SELECT Count(Id) FROM [User] WHERE [Account] = @account", parameterList).ToString()); if (accountCount > 0) { result.Result = UserRegisterResultEnum.AccountInUse; return(result); } DomainEntity domain = new DomainEntity(); domain.LastUpdateTime = DateTime.Now; _domainManager.Create(domain); UserEntity user = new UserEntity() { Account = args.Account, Password = args.Password, Name = args.Name, MobilePhone = args.MobilePhone, Email = args.Email, Domain = domain.Id, DomainOwner = true, RegisterTime = DateTime.Now }; result.User = user; result.Domain = domain; _dataBase.Insert(user); } result.Result = UserRegisterResultEnum.Success; return(result); }
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)); } }