public static bool SelectUserSave(int id, out UserSave entry) { entry = null; var locked = false; if (!IsConnected) { return(false); } try { using (MySqlCommand _cmd = _connection.CreateCommand()) { _cmd.CommandText = $"SELECT data FROM {tb_01} WHERE id={id};"; Monitor.Enter(_connection, ref locked); using (MySqlDataReader _result = _cmd.ExecuteReader()) { if (_result.HasRows && _result.Read()) { entry = _result.GetProtoBuf <UserSave>(0); return(true); } } } return(false); } catch { return(false); } finally { if (locked) { Monitor.Exit(_connection); } } }
public ActionResult Login([FromBody]UserSave loginUser) { if (loginUser == null || string.IsNullOrEmpty(loginUser.UserName)) { return Ok(new { success = false, error = "用户名/用户邮箱不能为空." }); } var userInfo = userDataDapper.FindUser(loginUser.UserName); if (userInfo != null) { if (userInfo.Password == Tools.GetMD5(loginUser.Password)) { string token = encryptionTools.Crypt($"{userInfo.ID}|{userInfo.UserName}"); userService.WriteUserToken(userInfo, token); return Ok(new { success = true, token = token, messgae = "登录成功!", data = userInfo }); } else { return Ok(new { success = false, error = "密码错误!" }); } } else { return Ok(new { success = false, error = "找不到用户信息或密码错误!" }); } }
public async System.Threading.Tasks.Task Save_User() { ApiController CtrlFactory(HttpRequestMessage message, IUmbracoContextAccessor umbracoContextAccessor, UmbracoHelper helper) { //setup some mocks Umbraco.Core.Configuration.GlobalSettings.HasSmtpServer = true; var userServiceMock = Mock.Get(Current.Services.UserService); userServiceMock.Setup(service => service.Save(It.IsAny <IUser>(), It.IsAny <bool>())) .Callback((IUser u, bool raiseEvents) => { u.Id = 1234; }); userServiceMock.Setup(service => service.GetAllUserGroups(It.IsAny <int[]>())) .Returns(new[] { Mock.Of <IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers") }); userServiceMock.Setup(service => service.GetUserGroupsByAlias(It.IsAny <string[]>())) .Returns(new[] { Mock.Of <IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers") }); userServiceMock.Setup(service => service.GetUserById(It.IsAny <int>())) .Returns((int id) => id == 1234 ? new User(1234, "Test", "*****@*****.**", "*****@*****.**", "", new List <IReadOnlyUserGroup>(), new int[0], new int[0]) : null); var usersController = new UsersController( Factory.GetInstance <IGlobalSettings>(), umbracoContextAccessor, Factory.GetInstance <ISqlContext>(), Factory.GetInstance <ServiceContext>(), Factory.GetInstance <AppCaches>(), Factory.GetInstance <IProfilingLogger>(), Factory.GetInstance <IRuntimeState>(), helper); return(usersController); } var userSave = new UserSave { Id = 1234, Email = "*****@*****.**", Username = "******", Culture = "en", Name = "Test", UserGroups = new[] { "writers" } }; var runner = new TestRunner(CtrlFactory); var response = await runner.Execute("Users", "PostSaveUser", HttpMethod.Post, new ObjectContent <UserSave>(userSave, new JsonMediaTypeFormatter())); var obj = JsonConvert.DeserializeObject <UserDisplay>(response.Item2); Assert.AreEqual(userSave.Name, obj.Name); Assert.AreEqual(1234, obj.Id); Assert.AreEqual(userSave.Email, obj.Email); var userGroupAliases = obj.UserGroups.Select(x => x.Alias).ToArray(); foreach (var group in userSave.UserGroups) { Assert.IsTrue(userGroupAliases.Contains(group)); } }
void Awake() { if (userP == null) { userP = this; } }
public PlayerDataManager() { if (ModelContr == null) { ModelContr = new ModelController(); } SerializedController = new SerializedController(); UserSave = new UserSave(); var readSaveData = UserSave.Read(); DebugLogger.Log(null, "[Init] save data exists: " + (readSaveData != null)); UserSave = (UserSave)(readSaveData ?? UserSave); UserSave.Init(); #if UNITY_EDITOR UnityEditor.EditorApplication.playModeStateChanged += EditorApplicationOnPlayModeStateChanged; #endif Observable.OnceApplicationQuit().Subscribe(_ => OnceApplicationQuit()); Observable.EveryApplicationPause().Subscribe(_ => OnApplicationPause()); }
public async Task SaveUser(UserSave completeUser, int id = 0) { if (id == 0) { var address = EntityBuilder.Call<Address>(completeUser); var userBuilder = EntityBuilder.Call<User>(completeUser); var size = await personRepository.CountByDocument<User>(userBuilder.CPF, Convert.ToInt16(userBuilder.Role)); if (size > 0) throw new EntityUniq("CPF já cadastrado"); await entityRepository.Save(address); userBuilder.AddressId = address.Id; await entityRepository.Save(userBuilder); } else { var user = await entityRepository.FindById<User>(id); if (user == null || user.Id == 0) throw new EntityNotFound("Usuário não encontrado"); var address = EntityBuilder.Call<Address>(completeUser); var userBuilder = EntityBuilder.Call<User>(completeUser); userBuilder.Id = user.Id; userBuilder.AddressId = user.AddressId; address.Id = Convert.ToInt32(user.AddressId); var size = await personRepository.CountByIdAndDocument<User>(userBuilder.Id, userBuilder.CPF, Convert.ToInt16(userBuilder.Role)); if (size > 0) throw new EntityUniq("CPF já cadastrado"); await entityRepository.Update(address); await entityRepository.Update(user); } }
public List <bool> LoadUserLevelListLocal() { UserData _myUserData = UserSave.LoadUser(); _Instance._userLevelsList = _myUserData._userLevelsListData; return(_Instance._userLevelsList); }
public int LoadUserHighScore() { UserData _myUserData = UserSave.LoadUser(); _Instance._userHighScore = _myUserData._userHighScoreData; return(_Instance._userHighScore); }
public async Task <bool> Save(UserSave action) { Data.Models.UserAction userAction = new Data.Models.UserAction(); userAction.Action = action.action; userAction.TimeStamp = action.timestamp; userAction.UserId = action.userId; return(await Repository.Save(userAction)); }
private void Awake() { SinglePatern(); UserData _myUserData = UserSave.LoadUser(); CreateANewUserIfNecessary(_myUserData); }
public bool LoadIsSoundOnLocal() { UserData _myUserData = UserSave.LoadUser(); _Instance._IsSoundOn = _myUserData._IsSoundOnData; return(_Instance._IsSoundOn); }
public HttpResponseMessage Create(UserSave user) { var createdUser = this.userService.Save(Mapper.Map <UserSaveDTO>(user)); if (createdUser.OverallErrors != null && createdUser.OverallErrors.Count > 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, createdUser)); } return(Request.CreateResponse(HttpStatusCode.OK, Mapper.Map <Models.User>(createdUser.ValidatedUser))); }
private UserInfo AddUser(UserSave registerUser, string activatecode) { var insertUser = new UserInfo(); insertUser.Email = registerUser.Email; insertUser.UserName = registerUser.UserName; insertUser.Password = registerUser.Password; insertUser.ActivatedCode = activatecode; _userDapper.InsertUser(insertUser); return(insertUser); }
private void CheckRegisterUser(UserSave registerUser) { if (registerUser == null || string.IsNullOrEmpty(registerUser.Email) || string.IsNullOrEmpty(registerUser.UserName)) { throw new Exception("用户名/用户邮箱不能为空."); } if (_context.Users.Any(u => u.UserName == registerUser.UserName)) { throw new Exception("用户已存在!"); } }
private static void CheckLogin(UserSave loginUser, UserInfo userInfo) { if (userInfo == null) { throw new Exception("找不到用户信息或密码错误!"); } if (userInfo.Password != Tools.GetMD5(loginUser.Password)) { throw new Exception("用户名/密码错误."); } }
private UserInfo AddUser(UserSave registerUser, string activatecode) { var insertUser = new UserInfo(); insertUser.Email = registerUser.Email; insertUser.UserName = registerUser.UserName; insertUser.Password = registerUser.Password; insertUser.ActivatedCode = activatecode; _context.Users.Add(insertUser); _context.SaveChanges(); return(insertUser); }
public JObject SaveUser([FromBody] UserSave userSave) { MainDBContext mainDBContext = new MainDBContext(); var user = mainDBContext.Users.Find(userSave.Id); user.Nickname = userSave.nickname; mainDBContext.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified; mainDBContext.SaveChanges(); return(JObject.Parse(JsonConvert.SerializeObject(new UniversalActionNet { ResultCode = ResultCode.Success }))); }
private void CheckRegisterUser(UserSave registerUser) { if (registerUser == null || string.IsNullOrEmpty(registerUser.Email) || string.IsNullOrEmpty(registerUser.UserName)) { throw new Exception("用户名/用户邮箱不能为空."); } var checkUser = _userDapper.FindUser(registerUser.UserName); if (checkUser != null) { throw new Exception("用户已存在!"); } }
public JObject SaveUser([FromBody] UserSave userSave) { MainDBContext mainDBContext = new MainDBContext(); var user = mainDBContext.Users.Find(userSave.ID); user.Birthday = userSave.Age; user.Nickname = userSave.Nickname; user.Sex = userSave.Sex; mainDBContext.SaveChanges(); return(JObject.Parse(JsonConvert.SerializeObject(new UniversalActionNet { ResultCode = ResultCode.Success }))); }
public Tuple <string, UserInfo> Register(UserSave registerUser) { CheckRegisterUser(registerUser); string activatecode = Tools.GetSha256(registerUser.UserName + registerUser.Email + DateTime.Now); SendActivateEmail(registerUser, activatecode); UserInfo insertUser = AddUser(registerUser, activatecode); var userInfo = _context.Users.FirstOrDefault(u => u.UserName == registerUser.UserName); string token = userInfo.NewLoginToken; WriteUserToken(userInfo, token); return(Tuple.Create <string, UserInfo>(token, userInfo)); }
public Tuple <string, UserInfo> Login(UserSave loginUser) { if (loginUser == null || string.IsNullOrEmpty(loginUser.UserName)) { throw new Exception("用户名/用户邮箱不能为空."); } var userInfo = _context.Users.FirstOrDefault(u => u.UserName == loginUser.UserName); CheckLogin(loginUser, userInfo); string token = userInfo.NewLoginToken; WriteUserToken(userInfo, token); return(Tuple.Create <string, UserInfo>(token, userInfo)); }
public async void Save_User() { var runner = new TestRunner((message, helper) => { //setup some mocks Umbraco.Core.Configuration.GlobalSettings.HasSmtpServer = true; var userServiceMock = Mock.Get(helper.UmbracoContext.Application.Services.UserService); userServiceMock.Setup(service => service.Save(It.IsAny <IUser>(), It.IsAny <bool>())) .Callback((IUser u, bool raiseEvents) => { u.Id = 1234; }); userServiceMock.Setup(service => service.GetAllUserGroups(It.IsAny <int[]>())) .Returns(new[] { Mock.Of <IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers") }); userServiceMock.Setup(service => service.GetUserGroupsByAlias(It.IsAny <string[]>())) .Returns(new[] { Mock.Of <IUserGroup>(group => group.Id == 123 && group.Alias == "writers" && group.Name == "Writers") }); userServiceMock.Setup(service => service.GetUserById(It.IsAny <int>())) .Returns(new User(1234, "Test", "*****@*****.**", "*****@*****.**", "", new List <IReadOnlyUserGroup>(), new int[0], new int[0])); //we need to manually apply automapper mappings with the mocked applicationcontext InitializeMappers(helper.UmbracoContext.Application); return(new UsersController(helper.UmbracoContext)); }); var userSave = new UserSave { Id = 1234, Email = "*****@*****.**", Username = "******", Culture = "en", Name = "Test", UserGroups = new[] { "writers" } }; var response = await runner.Execute("Users", "PostSaveUser", HttpMethod.Post, new ObjectContent <UserSave>(userSave, new JsonMediaTypeFormatter())); var obj = JsonConvert.DeserializeObject <UserDisplay>(response.Item2); Assert.AreEqual(userSave.Name, obj.Name); Assert.AreEqual(1234, obj.Id); Assert.AreEqual(userSave.Email, obj.Email); var userGroupAliases = obj.UserGroups.Select(x => x.Alias).ToArray(); foreach (var group in userSave.UserGroups) { Assert.IsTrue(userGroupAliases.Contains(group)); } }
private void SendActivateEmail(UserSave registerUser, string token) { EmailInfo email = new EmailInfo(); email.Body = $"Hi,{registerUser.UserName}. <br>欢迎您注册地图搜租房(woyaozufang.live),你的账号已经注册成功." + "<br/>为了保证您能正常体验网站服务,请点击下面的链接完成邮箱验证以激活账号." + $"<br><a href='https://woyaozufang.live/Account/Activated?activatedCode={token}'>https://woyaozufang.live/Account/Activate?activatedCode={token}</a> " + "<br>如果您以上链接无法点击,您可以将以上链接复制并粘贴到浏览器地址栏打开." + "<br>此信由系统自动发出,系统不接收回信,因此请勿直接回复。" + "<br>如果有其他问题咨询请发邮件到[email protected]."; email.Receiver = registerUser.Email; email.Subject = "地图找租房-激活账号"; email.ReceiverName = registerUser.UserName; _emailService.Send(email); }
public async Task Save_User() { string url = PrepareApiControllerUrl <UsersController>(x => x.PostSaveUser(null)); IUserService userService = GetRequiredService <IUserService>(); User user = new UserBuilder() .AddUserGroup() .WithAlias("writer") // Needs to be an existing alias .Done() .Build(); userService.Save(user); var userSave = new UserSave { Id = user.Id, Email = user.Email, Username = user.Username, Culture = "en", Name = user.Name, UserGroups = user.Groups.Select(x => x.Alias).ToArray() }; // Act HttpResponseMessage response = await Client.PostAsync( url, new StringContent(JsonConvert.SerializeObject(userSave), Encoding.UTF8, MediaTypeNames.Application.Json)); // Assert Assert.Multiple(() => { Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); string body = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); body = body.TrimStart(AngularJsonMediaTypeFormatter.XsrfPrefix); UserDisplay actual = JsonConvert.DeserializeObject <UserDisplay>(body, new JsonSerializerSettings { ContractResolver = new IgnoreRequiredAttributesResolver() }); Assert.AreEqual(userSave.Name, actual.Name); Assert.AreEqual(userSave.Id, actual.Id); Assert.AreEqual(userSave.Email, actual.Email); string[] userGroupAliases = actual.UserGroups.Select(x => x.Alias).ToArray(); CollectionAssert.AreEquivalent(userSave.UserGroups, userGroupAliases); }); }
public async Task DataHandlerTestStorable() { using var store = GetDocumentStore(); using var session = store.OpenAsyncSession(); var command = new UserSave { Session = session, Model = UserData.GetFirst() }; var handler = new DataHandler(session) { User = StandardUser }; handler.User.Id.Should().Be(StandardUser.Id); await handler.Execute(command); }
public JsonResult GetUser() { UserSave datas = new UserSave(); var ses = (UserSave)Session[Constant.USER_SESSION]; if (ses == null) { datas.ID = 0; } else { datas.ID = ses.ID; datas.HoTen = ses.HoTen; datas.UserName = ses.UserName; } return(Json(datas, JsonRequestBehavior.AllowGet)); }
public static bool UpdateUserSave(int id, UserSave entry) { if (!IsConnected) { return(false); } try { using (MySqlCommand _cmd = _connection.CreateCommand()) { _cmd.CommandText = $"UPDATE {tb_01} SET data=@data WHERE id={id};"; _cmd.Parameters.AddWithValue("data", entry.GetBytes()); return(_cmd.ExecuteNonQuery() == 1); } } catch { return(false); } }
public async Task UserSaveDataTest() { using var store = GetDocumentStore(); using var session = store.OpenAsyncSession(); var model = UserData.GetSecond(); var persist = new UserSave { Session = session, Model = model }; await persist.Execute(); persist.Confirm.Should().NotBeNull(); persist.Confirm.Identity.Should().Be(model.Id); persist.Confirm.Success.Should().BeTrue(); Assert.That(persist.Model, Is.DeepEqualTo(model)); }
// Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate // Umbraco.Code.MapAll -TourData -SessionTimeout -EmailConfirmedDate -InvitedDate -SecurityStamp -Avatar // Umbraco.Code.MapAll -ProviderUserKey -RawPasswordValue -RawPasswordAnswerValue -PasswordQuestion -Comments // Umbraco.Code.MapAll -IsApproved -IsLockedOut -LastLoginDate -LastPasswordChangeDate -LastLockoutDate // Umbraco.Code.MapAll -FailedPasswordAttempts private void Map(UserSave source, IUser target, MapperContext context) { target.Name = source.Name; target.StartContentIds = source.StartContentIds ?? Array.Empty <int>(); target.StartMediaIds = source.StartMediaIds ?? Array.Empty <int>(); target.Language = source.Culture; target.Email = source.Email; target.Key = source.Key; target.Username = source.Username; target.Id = source.Id; target.ClearGroups(); var groups = _userService.GetUserGroupsByAlias(source.UserGroups.ToArray()); foreach (var group in groups) { target.AddGroup(group.ToReadOnlyGroup()); } }
public ActionResult Register([FromBody]UserSave registerUser) { if (registerUser == null || string.IsNullOrEmpty(registerUser.Email) || string.IsNullOrEmpty(registerUser.UserName)) { return Ok(new { success = false, error = "用户名/用户邮箱不能为空." }); } var checkUser = userDataDapper.FindUser(registerUser.UserName); if (checkUser != null) { return Ok(new { success = false, error = "用户已存在!" }); } try { string token = Tools.GetMD5(encryptionTools.Crypt(registerUser.UserName + registerUser.Email)); EmailInfo email = new EmailInfo(); email.Body = $"Hi,{registerUser.UserName}. <br>欢迎您注册地图搜租房(woyaozufang.live),你的账号已经注册成功." + "<br/>为了保证您能正常体验网站服务,请点击下面的链接完成邮箱验证以激活账号." + $"<br><a href='https://woyaozufang.live/Account/Activated?activatedCode={token}'>https://woyaozufang.live/Account/Activate?activatedCode={token}</a> " + "<br>如果您以上链接无法点击,您可以将以上链接复制并粘贴到浏览器地址栏打开." + "<br>此信由系统自动发出,系统不接收回信,因此请勿直接回复。" + "<br>如果有其他问题咨询请发邮件到[email protected]."; email.Receiver = registerUser.Email; email.Subject = "地图找租房-激活账号"; email.ReceiverName = registerUser.UserName; emailService.Send(email); var insertUser = new UserInfo(); insertUser.Email = registerUser.Email; insertUser.UserName = registerUser.UserName; insertUser.Password = insertUser.Password; insertUser.ActivatedCode = token; userDataDapper.InsertUser(insertUser); var userInfo = userDataDapper.FindUser(insertUser.UserName); string loginToken = encryptionTools.Crypt($"{userInfo.ID}|{userInfo.UserName}"); userService.WriteUserToken(userInfo, loginToken); return Ok(new { success = true, message = "注册成功!", token = loginToken, data = userInfo }); } catch (Exception ex) { return Ok(new { success = false, error = ex.ToString() }); } }