public async Task <object> Register([FromBody] RegisterParam registerParam) { var user = new ApplicationUser { UserName = registerParam.UserName }; var result = await userManager.CreateAsync(user, registerParam.Password); if (result.Succeeded) { var isRoleExist = await roleManager.RoleExistsAsync("Admin"); if (!isRoleExist) { result = await roleManager.CreateAsync(new IdentityRole { Name = "Admin" }); } if (!result.Succeeded) { throw new ApplicationException($"Role creation failed, reason {string.Join(", ", result.Errors.Select(e => e.Description))}"); } result = await userManager.AddToRoleAsync(user, "Admin"); if (result.Succeeded) { await signInManager.SignInAsync(user, false); return(await generateToken(user)); } } throw new ApplicationException($"Register Failed, reason {string.Join(", ", result.Errors.Select(e => e.Description))}"); }
public bool Register(RegisterParam storeInfo) { bool status = false; if (storeInfo.UserType == 1)//音乐人 { var p = new DynamicParameters(); p.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output); helper.Execute($@"insert into [User] (Phone,[Password],UserType,Status) values ('{storeInfo.Phone}','{Util.MD5Encrypt(storeInfo.Password)}',{1},{1});SELECT @Id=SCOPE_IDENTITY()", p); int userId = p.Get <int>("@Id"); var result = helper.Execute($@"insert into SingerDetailInfo (UserId,CreateTime,Enabled,SingerName) values ({userId},'{DateTime.Now}',{1},'{storeInfo.Phone}')"); status = result > 0 ? true : false; } else if (storeInfo.UserType == 2)//商家 { Guid storeCode = Guid.NewGuid(); var p = new DynamicParameters(); p.Add("@Id", dbType: DbType.Int32, direction: ParameterDirection.Output); helper.Execute($@"insert into [User] (Phone,[Password],UserType,Status,IsMain,StoreCode,StoreManage,SongManage,UserManage) values ('{storeInfo.Phone}','{Util.MD5Encrypt(storeInfo.Password)}',{2},{1},{1},'{storeCode}',{1},{1},{1});SELECT @Id=SCOPE_IDENTITY()", p); int userId = p.Get <int>("@Id"); var result = helper.Execute($@"insert into StoreDetailInfo (UserId,CreateTime,Enabled,StoreName,Province,City,County,DetailAddress,StoreTypeId) values ({userId},'{DateTime.Now}',{1},'{storeInfo.StoreName}',{storeInfo.Province},{storeInfo.City},{storeInfo.County},'{storeInfo.DetailAddress}',{storeInfo.StoreTypeId})"); status = result > 0 ? true : false; } return(status); }
public ActionResult <Sim> PostSim(RegisterParam param) { var simGroup = _userRepository.GetSimGroup((Guid)param.SimGroupId); if (_context.Sim.Any(s => s.UserName == param.UserName && s.SimGroup.UserNameSuffix == simGroup.UserNameSuffix)) { ModelState.AddModelError(nameof(Sim.UserName), Messages.Duplicate); return(ValidationProblem(ModelState)); } if (param.UserName == null || "".Equals(param.UserName)) { param.UserName = GenerateRandomPassword(16); while (_context.Sim.Any(s => s.UserName == param.UserName && s.SimGroup.UserNameSuffix == simGroup.UserNameSuffix)) { param.UserName = GenerateRandomPassword(16); } } if (param.Password == null || "".Equals(param.Password)) { param.Password = GenerateRandomPassword(32); } var sim = new Sim() { Msisdn = param.Msisdn, Imsi = param.Imsi, IccId = param.IccId, UserName = param.UserName, Password = param.Password, SimGroup = simGroup }; try { _userRepository.Create(sim); } catch (DbUpdateException) { if (_context.Sim.Any(s => s.Msisdn == param.Msisdn)) { ModelState.AddModelError(nameof(Sim.Msisdn), Messages.Duplicate); } if (_context.Sim.Any(s => s.IccId == param.IccId)) { ModelState.AddModelError(nameof(Sim.IccId), Messages.Duplicate); } if (_context.Sim.Any(s => s.Imsi == param.Imsi)) { ModelState.AddModelError(nameof(Sim.Imsi), Messages.Duplicate); } if (!ModelState.IsValid) { return(ValidationProblem(ModelState)); } throw; } return(CreatedAtAction("GetSim", new { id = sim.Id }, sim)); }
public IActionResult PutSim(Guid id, RegisterParam param) { var sim = _userRepository.GetSim(id); var simGroup = _userRepository.GetSimGroup((Guid)param.SimGroupId); if (_context.Sim.Any(s => s.Id != id && s.UserName == param.UserName && s.SimGroup.UserNameSuffix == sim.SimGroup.UserNameSuffix)) { ModelState.AddModelError(nameof(Sim.UserName), Messages.Duplicate); return(ValidationProblem(ModelState)); } if (param.UserName == null || "".Equals(param.UserName)) { param.UserName = GenerateRandomPassword(16); while (_context.Sim.Any(s => s.UserName == param.UserName && s.SimGroup.UserNameSuffix == sim.SimGroup.UserNameSuffix)) { param.UserName = GenerateRandomPassword(16); } } if (param.Password == null || "".Equals(param.Password)) { param.Password = GenerateRandomPassword(32); } sim.Msisdn = param.Msisdn; sim.IccId = param.IccId; sim.Imsi = param.Imsi; sim.UserName = param.UserName; sim.Password = param.Password; sim.SimGroup = simGroup; try { _userRepository.Update(sim); return(Ok(_userRepository.GetSim(id))); } catch (DbUpdateException) { if (_context.Sim.Any(s => s.Id != id && s.Msisdn == param.Msisdn)) { ModelState.AddModelError(nameof(Sim.Msisdn), Messages.Duplicate); } if (_context.Sim.Any(s => s.Id != id && s.IccId == param.IccId)) { ModelState.AddModelError(nameof(Sim.IccId), Messages.Duplicate); } if (_context.Sim.Any(s => s.Id != id && s.Imsi == param.Imsi)) { ModelState.AddModelError(nameof(Sim.Imsi), Messages.Duplicate); } if (!ModelState.IsValid) { return(ValidationProblem(ModelState)); } throw; } }
public ActionResult <Sim> PostSimMine(RegisterParam param) { var user = _userRepository.GetEndUser(Guid.Parse(User.Identity.Name)); var simGroup = _userRepository.GetSimGroup((Guid)param.SimGroupId); if (user.Domain.Organization.Code != simGroup.Organization.Code) { ModelState.AddModelError("Role", Messages.InvalidRole); return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden)); } return(PostSim(param)); }
public ActionResult <MultiFactor> PostMultiFactor(RegisterParam param) { var simDevice = _userRepository.GetSimAndDevice((Guid)param.SimAndDeviceId); var endUser = _userRepository.GetEndUser((Guid)param.UserId); var availablePeriod = endUser.AvailablePeriods.OrderByDescending(a => a.StartDate).FirstOrDefault(); if (param.StartDate < simDevice.StartDate || param.StartDate > simDevice.EndDate || availablePeriod?.StartDate > param.StartDate || availablePeriod?.EndDate < param.StartDate) { ModelState.AddModelError(nameof(param.StartDate), Messages.OutOfDate); } if (param.EndDate < simDevice.StartDate || param.EndDate > simDevice.EndDate || availablePeriod?.StartDate > param.EndDate || availablePeriod?.EndDate < param.EndDate) { ModelState.AddModelError(nameof(param.EndDate), Messages.OutOfDate); } if (!ModelState.IsValid) { return(ValidationProblem(ModelState)); } if (_context.MultiFactor.Any(s => s.SimAndDevice.Id == simDevice.Id && s.EndUser.Id == endUser.Id)) { ModelState.AddModelError(nameof(MultiFactor), Messages.Duplicate); } if (!ModelState.IsValid) { return(ValidationProblem(ModelState)); } var multiFactor = new MultiFactor() { SimAndDevice = simDevice, EndUser = endUser, StartDate = (DateTime)param.StartDate, EndDate = param.EndDate, ClosedNwIp = param.ClosedNwIp }; try { _userRepository.Create(multiFactor); } catch (DbUpdateException) { throw; } return(CreatedAtAction("GetMultiFactor", new { id = multiFactor.Id }, multiFactor)); }
public ActionResult <SimAndDevice> PostSimAndDeviceMine(RegisterParam param) { var sim = _userRepository.GetSim((Guid)param.SimId); var user = _userRepository.GetEndUser(Guid.Parse(User.Identity.Name)); if (sim.SimGroup.Organization.Code != user.Domain.Organization.Code) { ModelState.AddModelError("Role", Messages.InvalidRole); return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden)); } if (!_context.Device.Any(d => d.Id == param.DeviceId && d.Domain.Organization.Code == user.Domain.Organization.Code) && _context.Device.Any(d => d.Id == param.DeviceId)) { ModelState.AddModelError("Role", Messages.InvalidRole); return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden)); } return(PostSimAndDevice(param)); }
public bool Register(RegisterParam parms) { try { var model = new FewMainUsers() { AddTime = DateTime.Now, Email = parms.Email, Mobile = parms.Mobile, Password = EncryptHelper.GetMD5(parms.Password), UserName = parms.UserName, Weixin = parms.Weixin }; Add(model); return(SaveChanges() > 0); } catch (Exception ex) { return(false); throw; } }
public ActionResult <SimAndDevice> PostSimAndDevice(RegisterParam param) { var sim = _userRepository.GetSim((Guid)param.SimId); var device = _userRepository.GetDevice((Guid)param.DeviceId); if (param.StartDate < device.StartDate || param.StartDate > device.EndDate) { ModelState.AddModelError(nameof(param.StartDate), Messages.OutOfDate); } if (param.EndDate < device.StartDate || param.EndDate > device.EndDate) { ModelState.AddModelError(nameof(param.EndDate), Messages.OutOfDate); } if (!ModelState.IsValid) { return(ValidationProblem(ModelState)); } var simDevice = new SimAndDevice() { Sim = sim, Device = device, StartDate = (DateTime)param.StartDate, EndDate = param.EndDate, AuthenticationDuration = (int)param.AuthenticationDuration, IsolatedNw2Ip = param.IsolatedNw2Ip }; if (_context.SimAndDevice.Any(s => s.Sim.Id == simDevice.Sim.Id && s.Device.Id == simDevice.Device.Id)) { ModelState.AddModelError(nameof(SimAndDevice), Messages.Duplicate); return(ValidationProblem(ModelState)); } try { _userRepository.Create(simDevice); } catch (DbUpdateException) { return(Conflict()); //throw; } return(CreatedAtAction("GetSimAndDevice", new { id = simDevice.Id }, simDevice)); }
public ResponseResultDto <bool> Register(RegisterParam userInfo) { var res = userRepository.ValidateSmsCode(userInfo.Phone, userInfo.SmsCode); if (!res.Item1) { return(new ResponseResultDto <bool> { IsSuccess = false, ErrorMessage = "验证码不正确", Result = false }); } userRepository.DeleteSmsCode(userInfo.Phone, userInfo.SmsCode); bool isSussess = false; string errorMessage = string.Empty; bool result = false; if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.Phone) || string.IsNullOrWhiteSpace(userInfo.Password) || userInfo.UserType < 1) { return(new ResponseResultDto <bool> { IsSuccess = false, ErrorMessage = "参数异常", Result = result }); } if (userRepository.Register(userInfo)) { isSussess = true; result = true; } return(new ResponseResultDto <bool> { IsSuccess = isSussess, ErrorMessage = errorMessage, Result = result }); }
public ActionResult Register(RegisterParam parms) { var result = new ResultModel(); if (parms.Password != parms.RePassword) { result = new ResultModel() { IsSuccess = false, Msg = "两次密码不一致" }; } else if (CacheHelper.Session["registercode"].ToString() != parms.ValidateCode) { result = new ResultModel() { IsSuccess = false, Msg = "图片验证码错误" }; } var isRegister = userBll.Register(parms); if (isRegister) { userBll.Login(new LoginParam() { Password = parms.Password, UserName = parms.UserName }); //注册成功跳转到首页 return(RedirectToAction("Index", "Home")); } else { result = new ResultModel() { IsSuccess = false, Msg = "注册失败" }; return(Json(result)); } }
public ActionResult <MultiFactor> PostMultiFactorMine(RegisterParam param) { var user = _userRepository.GetEndUser(Guid.Parse(User.Identity.Name)); var simDevice = _userRepository.GetSimAndDevice((Guid)param.SimAndDeviceId); var endUser = _userRepository.GetEndUser((Guid)param.UserId); if (simDevice.Sim.SimGroup.Organization.Code != user.Domain.Organization.Code) { ModelState.AddModelError("Role", Messages.InvalidRole); return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden)); } if (simDevice.Device.Domain.OrganizationCode != user.Domain.Organization.Code) { ModelState.AddModelError("Role", Messages.InvalidRole); return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden)); } if (endUser.Domain.OrganizationCode != user.Domain.Organization.Code) { ModelState.AddModelError("Role", Messages.InvalidRole); return(ValidationProblem(modelStateDictionary: ModelState, statusCode: StatusCodes.Status403Forbidden)); } return(PostMultiFactor(param)); }
public override IAuthIdentity Register(RegisterParam param) { throw new NotImplementedException(); }
/// <summary> /// Parses the action from a string array /// </summary> /// <param name="token">The action as string arry</param> /// <returns>True - If parsing was successful. False - If it was not</returns> protected override bool ParseFrom( params string[] token ) { if ( token.Length < 2 ) return false; _functionName = token[ 0 ]; _codeSize = UInt16.Parse( token[ 1 ] ); _Parameters = new List<RegisterParam>(); for ( int i = 2; i < token.Length; i++ ) { // // Parameter register preload // if ( token[ i ].Contains( "->" ) ) { string param = token[ i ].Substring( 0, token[ i ].IndexOf( "->" ) ); string reg = token[ i ].Substring( token[ i ].LastIndexOf( "->" ) + 1 ); byte regNum = Byte.Parse( reg ); RegisterParam p = new RegisterParam(); p.ParamName = param; p.Register = regNum; _Parameters.Add( p ); } else if ( token[ i ].Equals( "PreloadParent", StringComparison.InvariantCulture ) ) { _PreloadParentFlag = true; } else if ( token[ i ].Equals( "PreloadRoot", StringComparison.InvariantCulture ) ) { _PreloadRootFlag = true; } else if ( token[ i ].Equals( "SuppressSuper", StringComparison.InvariantCulture ) ) { _SuppressSuperFlag = true; } else if ( token[ i ].Equals( "PreloadSuper", StringComparison.InvariantCulture ) ) { _PreloadSuperFlag = true; } else if ( token[ i ].Equals( "SuppressArguments", StringComparison.InvariantCulture ) ) { _SuppressArgumentsFlag = true; } else if ( token[ i ].Equals( "PreloadArguments", StringComparison.InvariantCulture ) ) { _PreloadArgumentsFlag = true; } else if ( token[ i ].Equals( "SuppressThis", StringComparison.InvariantCulture ) ) { _SuppressThisFlag = true; } else if ( token[ i ].Equals( "PreloadThis", StringComparison.InvariantCulture ) ) { _PreloadThisFlag = true; } else if ( token[ i ].Equals( "PreloadGlobal", StringComparison.InvariantCulture ) ) { _PreloadGlobalFlag = true; } else { // unknown option return false; } } return true; }
/// <summary> /// Parses all neccessary information from a source stream /// </summary> /// <param name="sourceStream">The source stream</param> /// <param name="sourceVersion">The version</param> protected override void Parse( System.IO.BinaryReader sourceStream, byte sourceVersion ) { _functionName = Helper.SwfStrings.SwfString( sourceVersion, sourceStream ); _numParams = sourceStream.ReadUInt16(); _numRegister = sourceStream.ReadByte(); BitStream bits = new BitStream( sourceStream.BaseStream ); _PreloadParentFlag = ( 0 != bits.GetBits( 1 ) ); _PreloadRootFlag = ( 0 != bits.GetBits( 1 ) ); _SuppressSuperFlag = ( 0 != bits.GetBits( 1 ) ); _PreloadSuperFlag = ( 0 != bits.GetBits( 1 ) ); _SuppressArgumentsFlag = ( 0 != bits.GetBits( 1 ) ); _PreloadArgumentsFlag = ( 0 != bits.GetBits( 1 ) ); _SuppressThisFlag = ( 0 != bits.GetBits( 1 ) ); _PreloadThisFlag = ( 0 != bits.GetBits( 1 ) ); uint reserved = bits.GetBits( 7 ); _PreloadGlobalFlag = ( 0 != bits.GetBits( 1 ) ); if ( 0 != reserved ) { throw new AVM1ExceptionByteCodeFormat( "ActionDefineFunction2 with reserved flags used" ); } if ( _SuppressArgumentsFlag && _PreloadArgumentsFlag ) { throw new AVM1ExceptionByteCodeFormat( "ActionDefineFunction2 Supress+Preload Arguments flag" ); } if ( _SuppressSuperFlag && _PreloadSuperFlag ) { throw new AVM1ExceptionByteCodeFormat( "ActionDefineFunction2 Supress+Preload Super flag" ); } if ( _SuppressThisFlag && _PreloadThisFlag ) { throw new AVM1ExceptionByteCodeFormat( "ActionDefineFunction2 Supress+Preload This flag" ); } // TODO: make sure this is correct _Parameters = new List<RegisterParam>(); for ( int i = 0; i < _numParams; i++ ) { RegisterParam rp = new RegisterParam(); rp.Register = sourceStream.ReadByte(); rp.ParamName = Helper.SwfStrings.SwfString( sourceVersion, sourceStream ); _Parameters.Add( rp ); } _codeSize = sourceStream.ReadUInt16(); // // Please see comment at ActionDefineFunction // // _code = Helper.SwfCodeReader.GetCode( _codeSize, sourceStream, sourceTag, sourceFile ); }
public static void AreEqual(RegisterParam expected, RegisterParam actual, string message) { Assert.AreEqual(expected.Name, actual.Name, message + ".Name"); Assert.AreEqual(expected.Register, actual.Register, message + ".Register"); }
/// <summary> /// 注册提交 /// </summary> /// <param name="param"></param> /// <returns></returns> public JsonResult AjaxRegister(RegisterParam param) { BaseResult res = new BaseResult(); bool isRegister = true;//是否注册成功 //检查用户是否存在 if (UserLogic.ExistsLoginName(param.LoginName)) { res.State = State.ExistsLoginName; res.Message = "用户名已存在!"; isRegister = false; } else if (UserLogic.ExistsPhoneNum(param.Phone)) { res.State = State.NumIsRegister; res.Message = "手机号码已被注册!"; isRegister = false; } if (isRegister) { //先去设备平台注册 RegisterModel rm = UserData.Register(param.LoginName, param.Pwd, param.Phone, param.IMEI); if (rm.User == null) {//注册失败直接返回 res.State = State.Falid; res.Message = rm.Message; isRegister = false; return(Json(res)); } User _u = new User(); _u.UserName = param.LoginName; _u.LoginName = param.LoginName; _u.Pwd = Encryption.AESEncrypt(param.Pwd); _u.RegisterTime = DateTime.Now; _u.PhoneNum = param.Phone; _u.Status = (int)Status.Normal; _u.HeadImgId = ConstVal.DefaultHeadImgId; _u.UserTypeId = 4;//居民 _u.APIUserId = rm.User.UserId; _u.UserInfo = ""; _u.Sex = 1; int i = UserLogic.SaveUser(_u); if (i > 0) { res.State = State.Success; res.Message = "注册成功!"; if (!string.IsNullOrWhiteSpace(param.IMEI)) { //检查设备 DeviceCheckModel dcm = DeviceData.CheckDevice(param.IMEI, _u.APIUserId ?? 0); //添加设备表 Device d = new Device { UserId = _u.Id, IconId = 3, Created = DateTime.Now, Imei = param.IMEI, Status = (int)Status.Normal, APIDeviceId = dcm.DeviceId, APIDeviceModel = dcm.Model }; DeviceLogic.SaveDevice(d); } } else { res.State = State.Falid; res.Message = "注册失败!"; isRegister = false; } } //记录操作日志 SaveUserLog("注册账号" + (isRegister ? "成功" : "失败") + ":" + res.Message, LogLevel.Info, param.LoginName, "AjaxRegister", "注册账号"); return(Json(res)); }
public virtual IAuthIdentity Register(RegisterParam param) { return(new Identity(new AppStoreRank.Data.Models.Account())); }