public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } ApiResult result = new ApiResult(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Constants.API_BASE_URL); UserRegisterInfo registerInfo = userRegisterModel.ToInfo(); using (var response = await client.PostAsJsonAsync <UserRegisterInfo>("Register", registerInfo)) { string apiResponse = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <ApiResult>(apiResponse); if (result.resultCode == ResultCode.SUCCESS) { HttpContext.Session.Set("_msg", Encoding.ASCII.GetBytes("You have been successfully registered for the Oracle DB Password Reset Service.")); byte[] bytes = null; HttpContext.Session.Set("_username", Encoding.ASCII.GetBytes("")); return(RedirectToPage("./Result")); } } } ViewData["Error"] = result.errMsg; return(Page()); }
public void getUserRegisterInfoTest() { RegisterViewModel rv = new RegisterViewModel { Account = 1234, Email = "1234", FullName = "1234", Password = "******", Phone = "1234", Status = "1234", UserID = "1234", UserRole = "1234", UserType = "1234" }; UserRegisterInfo expect = new UserRegisterInfo { Account = 1234, Email = "1234", FullName = "1234", Password = "******", Phone = "1234", Status = "1234", UserID = "1234", UserRole = "1234", UserType = "1234" }; UserRegisterInfo result = AccountHelper.getUserRegisterInfo(rv); Assert.AreEqual(expect.Account, result.Account); }
public UserRegisterInfo ToInfo() { UserRegisterInfo uri = new UserRegisterInfo(); uri.UserName = this.UserName; uri.EmailAddr = this.EmailAddr; uri.OraclePassword = this.OraclePwd; return(uri); }
public async Task <ActionResult <User> > RegisterPostUser(UserRegisterInfo user) { var password = BCrypt.Net.BCrypt.HashPassword(user.Password, _configuration["salt"]); var tUser = new User { Email = user.Email, Username = user.Username, Token = password }; _context.User.Add(tUser); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUser", new { id = tUser.UserId }, "User Created")); }
/// <summary> /// Registers new user /// </summary> /// <param name="userRegisterInfo">User registration data</param> /// <returns>response</returns> public async Task <Response <HttpResponseMessage> > RegisterAsync(UserRegisterInfo userRegisterInfo) { // getting response var response = await this._registerClient.PostAsync("api/register", this.ConstructContent(userRegisterInfo)); if (!response.IsSuccessStatusCode) { return(this.ConstructResponse(Status.Error, response)); } // reading response var responseString = await response.Content.ReadAsStringAsync(); // returning response return(this.ConstructResponse(Status.Ok, response)); }
public bool AddUserToRegister(UserRegisterInfo uri) { try { var dbConnection = this.GetConnection(); if (dbConnection.State == System.Data.ConnectionState.Closed) { dbConnection.Open(); _logger.LogInformation("oracle connection opened."); } if (dbConnection.State == System.Data.ConnectionState.Open) { using (OracleCommand cmd = dbConnection.CreateCommand()) { try { cmd.CommandText = @" INSERT INTO oracle_pwd_reset_users (id, username, emailAddr) VALUES( (select CASE WHEN max(ID) IS null THEN 1 ELSE max(ID) + 1 END AS NewID from oracle_pwd_reset_users), :username, :email)"; OracleParameter[] parameters = new OracleParameter[] { new OracleParameter("username", uri.UserName), new OracleParameter("email", uri.EmailAddr) }; cmd.Parameters.AddRange(parameters); _logger.LogDebug("execute oracle cmd insert user"); int r = cmd.ExecuteNonQuery(); dbConnection.Close(); _logger.LogInformation("oracle connection closed."); } catch (Exception ex) { _logger.LogError(ex, ex.Message, null); return(false); } } } } catch (Exception ex) { _logger.LogError(ex, ex.Message, null); return(false); } return(true); }
public ActionResult Register(UserRegisterInfo registerInfo) { this._logger.LogDebug("Register"); ApiResult result = new ApiResult(); if (IsRegistered(registerInfo.UserName)) { result.resultCode = ResultCode.USER_ALREADY_REGISTERED; result.errMsg = "User is already registerd. Do not need to register again."; } else { if (IsValidOracleUser(registerInfo.UserName)) { if (IsValidOraclePassword(registerInfo.UserName, registerInfo.OraclePassword)) { if (_oracleUserRepo.AddUserToRegister(registerInfo)) { result.resultCode = ResultCode.SUCCESS; result.errMsg = "Success"; } else { result.resultCode = ResultCode.REGISTER_USER_FAILED_IN_DB; result.errMsg = "Registration failed. The user could not be registered to the DB."; } } else { result.resultCode = ResultCode.INVALID_ORACLE_PASSWORD; result.errMsg = "The provided oracle password is incorrect. Registration failed."; } } else { result.resultCode = ResultCode.INVALID_ORACLE_USERNAME; result.errMsg = "The provided oracle username is incorrect. Registration failed."; } } AddInfoToAudit(registerInfo.UserName, result, ACTION.REGISTER.ToString()); return(Ok(result)); }
public IActionResult Post([FromBody] UserRegisterInfo userRegisterInfo) { // hashing password userRegisterInfo.Password = this._passwordHS.HashPassword(userRegisterInfo.Password); // register user var result = (int)this._dataManager.Operate <UserRegisterInfo, object>("CreateUser", userRegisterInfo); // if registration is not successful return Bad Request code if (result == -1) { return(new StatusCodeResult(400)); } // adding verification information this._verifier.AddVerificationInfo(userRegisterInfo.Username, userRegisterInfo.Email); // return Success code return(new StatusCodeResult(200)); }
public static void RegistryUser(UserRegisterInfo user) { var request = WebRequest.Create("user/register"); request.ContentType = "application/json"; request.Method = "POST"; using (var stream = new StreamWriter(request.GetRequestStream())) { var json = JsonConvert.SerializeObject(user); stream.Write(json); } var response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode != HttpStatusCode.OK) { throw new ServerException("Action: user / register"); } }
private string UserInsertByPhone(string phone) { string pwd = new UserBLL().GetRandomPassword(8);//随机密码 if (!phone.IsPhone()) { return("手机号码格式不正确"); } string strIp = Tool.WebFormHandler.GetIP(); string[] ips = strIp.Split(','); string realIp = ips.Length > 1 ? ips[1] : ips[0]; string result = Users.UserIsRegByIP(realIp); if (result != "1") { string dt = result.Split('|')[1]; return("注册失败:为防止恶意注册,请在" + dt + "后重新注册"); } Guid userid = Guid.NewGuid(); //var model = WXRegister.AddUserInfo(userid, _app, pwd, phone, "", "", // "", "", 0, realIp); string from = _app; if (!string.IsNullOrEmpty(_appUserId)) { from += "_" + _appUserId; } #region 写用户信息 UserRegisterInfo registerUser = new UserRegisterInfo(); registerUser.Id = userid; registerUser.ExtenderKey = ""; registerUser.UserName = string.Format("{0}wx{1}", phone, DateTime.Now.ToString("yyMMdd")); //针对重复注册特殊处理 registerUser.Pwd = pwd; registerUser.Email = string.Empty; registerUser.TelNo = phone; registerUser.ThirdPartyId = string.Empty; registerUser.ThirdPartyType = (int)ConstString.ThirdPartyType.TuandaiUser; registerUser.RegisterFrom = from; registerUser.RegisterIP = realIp; registerUser.OpenId = GlobalUtils.OpenId; registerUser.NickName = registerUser.UserName; string msg = string.Empty; var userBasicInfoInfo = new UserBLL().RegiserUser(registerUser, ref msg); if (userBasicInfoInfo != null && !string.IsNullOrEmpty(userBasicInfoInfo.ExtenderKey)) { //记录日志 SysLogHelper.WriteErrorLog("会员推广_AddUserInfo", "UserName:" + userBasicInfoInfo.UserName + ";ExtendKey:" + userBasicInfoInfo.ExtenderKey); } #endregion if (userBasicInfoInfo != null) { RegisterUserHandler.AsyncAfterRegister(_app, userBasicInfoInfo); if ((userBasicInfoInfo.uStatus ?? 0) == 1) { var isNewSmsRequest = ConfigHelper.getConfigString("IsNewSmsRequest", "0"); if (isNewSmsRequest == "0") { //改用新的发短信,邮件,系统消息 var messageSender = new MessageSend(); //var parameters = new Dictionary<string, object>(); //parameters.Add("User", model); //parameters.Add("CurrentDate", DateTime.Now); //parameters.Add("ExtenderKey", model.ExtenderKey); //messageSender.SendMessage2(eventCode: MessageTemplates.RegisterSuccess, parameters: parameters, mobile: model.TelNo, email: model.Email, userId: model.Id); //将生成的密码已短信方式发送给用户 var parameters = new Dictionary <string, object>(); parameters.Add("PassWord", pwd); messageSender.SendMessage2(option: SendOption.Sms, eventCode: MessageTemplates.BindMobile, parameters: parameters, mobile: userBasicInfoInfo.TelNo); } else { SmsRequest rechargeSuccessSmsRequest = new SmsRequest(); rechargeSuccessSmsRequest.EventCode = MsgTemplatesType.BindMobile; rechargeSuccessSmsRequest.PlatformSource = PlatformSource.WeiXin; rechargeSuccessSmsRequest.UserId = userBasicInfoInfo.Id; rechargeSuccessSmsRequest.EmailAddress = userBasicInfoInfo.Email; rechargeSuccessSmsRequest.Mobile = userBasicInfoInfo.TelNo; rechargeSuccessSmsRequest.Parameters = new Dictionary <string, object>(); rechargeSuccessSmsRequest.Parameters.Add("PassWord", pwd); string errorMessage = string.Empty; SmsClient.SendMessage(rechargeSuccessSmsRequest, ref errorMessage); } try { TuanDai.InfoSystem.Model.LoginLog loginLogEntity = new TuanDai.InfoSystem.Model.LoginLog(); loginLogEntity.Id = Guid.NewGuid().ToString(); loginLogEntity.UserId = userBasicInfoInfo.Id.ToString(); loginLogEntity.IpAddress = Tool.WebFormHandler.GetIP(); loginLogEntity.LoginDate = DateTime.Now; loginLogEntity.DeviceType = "WeiXin"; loginLogEntity.DeviceName = _app + "自动注册登录"; //LoginLogService logApi = new LoginLogService(); //logApi.AddLoginLog(loginLogEntity); TuanDai.WXApiWeb.SysLogHelper.AddLoginLog(loginLogEntity); } catch (Exception ex) { NetLog.WriteLoginHandler("写入注册成功登录日志出错", Tool.ExceptionHelper.GetExceptionMessage(ex)); } } #region 注册成功后自动登录 if (GlobalUtils.IsWeiXinBrowser) { string strOpenId = TuanDai.WXApiWeb.Common.WeiXinApi.GetUserWXOpenId(userBasicInfoInfo.Id); if (strOpenId.IsNotEmpty()) { GlobalUtils.WriteOpenIdToCookie(strOpenId.ToText()); } } WebUserAuth.SignIn(userid.ToString()); #endregion } else { return("添加用户失败"); } return(string.Empty); }