public void Init() { var en = CultureInfo.CreateSpecificCulture("en"); Thread.CurrentThread.CurrentCulture = en; Thread.CurrentThread.CurrentUICulture = en; helper = new FormHelper(); subscription = new Subscription(); mock = new MockClass(); months = new[] {new Month(1, "January"), new Month(1, "February")}; product = new Product("memory card", 10, (decimal) 12.30); user = new SimpleUser(); users = new[] { new SimpleUser(1, false), new SimpleUser(2, true), new SimpleUser(3, false), new SimpleUser(4, true) }; mock.Values = new[] { 2, 3 }; var controller = new HomeController(); var context = new ControllerContext(); context.PropertyBag.Add("product", product); context.PropertyBag.Add("user", user); context.PropertyBag.Add("users", users); context.PropertyBag.Add("roles", new[] { new Role(1, "a"), new Role(2, "b"), new Role(3, "c") }); context.PropertyBag.Add("sendemail", true); context.PropertyBag.Add("confirmation", "abc"); context.PropertyBag.Add("fileaccess", FileAccess.Read); context.PropertyBag.Add("subscription", subscription); context.PropertyBag.Add("months", months); context.PropertyBag.Add("mock", mock); helper.SetController(controller, context); }
public async Task<IdentityResult> RegisterUser(UserModel userModel) { SimpleUser user = new SimpleUser { UserName = userModel.UserName }; var result = await _userManager.CreateAsync(user, userModel.Password); return result; }
public async Task <bool> CreateAsync(SimpleUser userinfo, List <AnnexInfo> annexinfo, CancellationToken cancle = default(CancellationToken)) { if (annexinfo == null) { throw new ArgumentNullException(nameof(annexinfo)); } if (annexinfo.Count > 0) { Context.AddRange(annexinfo); await Context.SaveChangesAsync(cancle); } return(true); }
static void Main(string[] args) { Chat chat = new Chat(); SimpleUser user = new SimpleUser(chat); Moderator mod = new Moderator(chat); chat.Moderator = mod; chat.SimpleUser = user; mod.sendMessage("Message1"); user.sendMessage("Message2"); Console.ReadKey(); }
public void Single_AppliesExtraActions() { Mock <IObjectAction> action = new Mock <IObjectAction>(); Object actionObject = null; action.Setup(x => x.Enact(It.IsAny <IGenerationContext>(), It.IsAny <Object>())) .Callback((IGenerationSession session, Object dest) => { actionObject = dest; }); mUserGenerator.AddAction(action.Object); SimpleUser user = mUserGenerator.Get(); Assert.AreEqual(actionObject, user); }
public void TestLogout() { var simpleUser = new SimpleUser { Id = Guid.NewGuid(), Username = "******" }; userProvider.Setup(x => x.GetCurrentUser()).Returns(simpleUser); var results = controller.PostLogout(); userProvider.Verify(x => x.GetCurrentUser(), Times.Once()); userProvider.Verify(x => x.Clear(It.IsAny <IWebApiUser>()), Times.Once()); }
public async Task TestGetUserPermissionsAsync_UserHasPermission() { var resourceId = 1; var resourceType = "Program"; var foreignResourceId = 3; var resourceTypeId = 1; var foreignResourceCache = new ForeignResourceCache(foreignResourceId, resourceId, resourceTypeId, null, null, null); var principalId = 1; var permissionId = 2; var permissionName = "my permission"; var permissionModel = new PermissionModel { Id = permissionId, Name = permissionName }; var simpleUser = new SimpleUser { Id = Guid.NewGuid() }; var userPermissions = new List <IPermission>(); userPermissions.Add(new SimplePermission { IsAllowed = true, PermissionId = permissionId, PrincipalId = principalId, ResourceId = resourceId, ForeignResourceId = foreignResourceId, ResourceTypeId = resourceTypeId }); resourceService.Setup(x => x.GetResourceTypeId(It.IsAny <string>())).Returns(resourceTypeId); resourceService.Setup(x => x.GetResourceByForeignResourceIdAsync(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(foreignResourceCache); permissionService.Setup(x => x.GetPermissionByIdAsync(It.IsAny <int>())).ReturnsAsync(permissionModel); userProvider.Setup(x => x.GetPermissionsAsync(It.IsAny <IWebApiUser>())).ReturnsAsync(userPermissions); userProvider.Setup(x => x.GetPrincipalIdAsync(It.IsAny <IWebApiUser>())).ReturnsAsync(principalId); var permissions = await controller.GetUserPermissionsAsync(simpleUser, resourceType, foreignResourceId); Assert.AreEqual(1, permissions.Count()); var firstPermission = permissions.First(); Assert.AreEqual(permissionName, firstPermission.PermissionName); Assert.AreEqual(permissionModel.Id, firstPermission.PermissionId); resourceService.Verify(x => x.GetResourceTypeId(It.IsAny <string>()), Times.Once()); permissionService.Verify(x => x.GetPermissionByIdAsync(It.IsAny <int>()), Times.Once()); userProvider.Verify(x => x.GetPermissionsAsync(It.IsAny <IWebApiUser>()), Times.Once()); userProvider.Verify(x => x.GetPrincipalIdAsync(It.IsAny <IWebApiUser>()), Times.Once()); }
public async Task UpdateStatus(SimpleUser user, string id, int status, string message, ModifyTypeEnum mtype, string mtypememo) { string cn = await Context.ChargeInfos.Where(x => x.ID == id).Select(x => x.ChargeNo).FirstOrDefaultAsync(); ChargeInfo ci = new ChargeInfo() { ID = id, Status = status, UpdateTime = DateTime.Now, UpdateUser = user.Id, ChargeNo = cn, ConfirmMessage = message, SubmitUser = user.Id, SubmitTime = DateTime.Now }; var entry = Context.ChargeInfos.Attach(ci); entry.Property(c => c.Status).IsModified = true; entry.Property(c => c.UpdateUser).IsModified = true; entry.Property(c => c.UpdateTime).IsModified = true; if (message != null) { entry.Property(c => c.ConfirmMessage).IsModified = true; } if (status == 4) { entry.Property(c => c.SubmitTime).IsModified = true; entry.Property(c => c.SubmitUser).IsModified = true; } ModifyInfo mi = new ModifyInfo() { Id = Guid.NewGuid().ToString("N").ToLower(), ChargeId = id, CreateTime = DateTime.Now, CreateUser = user.Id, Department = user.OrganizationId, Status = status, Type = mtype, TypeMemo = mtypememo }; Context.ModifyInfos.Add(mi); await Context.SaveChangesAsync(); }
public string ScheduleMessage(SimpleUser adminContact, User userObj, TaskItem taskObj, Usertask userTask, TaskSchedule taskSchedule, int offset = 0) { //This will create an html email that looks nice var email = new EmailData(taskObj, userObj); var msg = new MessageData() { MessageId = Guid.NewGuid().ToString(), tags = new[] { taskObj.Title }, sender = adminContact, to = new[] { new SimpleUser() { name = userObj.name, email = userTask.ContactMethod == Enums.ContactType.Email ? userObj.email : userObj.Phone } }, htmlContent = email.BodyTemplate, textContent = taskObj.TaskDetails, subject = taskObj.Title, replyTo = adminContact, SendTime = taskSchedule?.Time ?? userTask.SendTime }; if (taskSchedule == null) { //Immediately send message if (userTask.SendNow) { return(BackgroundJob.Enqueue(() => SendMessage(msg, userTask.ContactMethod, userTask))); } //wait until you say so else { var offSet = msg.SendTime - DateTime.Now; return(BackgroundJob.Schedule(() => SendMessage(msg, userTask.ContactMethod, userTask), offSet)); } } else { var freq = GetCronString(taskSchedule); //TODO finish this, figure out logic RecurringJob.AddOrUpdate(taskSchedule.Id, () => SendMessage(msg, userTask.ContactMethod, userTask), freq, TimeZoneInfo.Local); return(taskSchedule.Id); //or do we schedule one at a time? //need to figure out how this will work with send once things //return BackgroundJob.Schedule(() => SendMessage(msg, userTask.ContactMethod, userTask), NextRun(taskSchedule, userTask, userObj)); //ScheduleNextMessage } }
public async Task TestGetUserPermissionsAsync_ResourceTypeDoesNotExist() { var foreignResourceId = 3; var resourceType = "Program"; var simpleUser = new SimpleUser { Id = Guid.NewGuid() }; resourceService.Setup(x => x.GetResourceTypeId(It.IsAny <string>())).Returns(default(int?)); var permissions = await controller.GetUserPermissionsAsync(simpleUser, resourceType, foreignResourceId); Assert.AreEqual(0, permissions.Count()); resourceService.Verify(x => x.GetResourceTypeId(It.IsAny <string>()), Times.Once()); }
protected void Page_Load(object sender, EventArgs e) { m_UserIDToRemove = _Request.Get <int>("uid", Method.Get, 0); if (_Request.IsClick("delete")) { Delete(); } m_UserToRemove = UserBO.Instance.GetSimpleUser(m_UserIDToRemove); if (m_UserToRemove == null) { ShowError(new UserNotExistsError("uid", m_UserIDToRemove)); } }
public async Task Load(SimpleUser user) { _user = user ?? throw new ArgumentNullException(nameof(user)); try { var onlineUsers = await _signalHelperFacade.ChatSignalHelper.GetOnlineUsers().ConfigureAwait(true); UpdateOnlineCappuUsers(onlineUsers); await CheckForActiveVote().ConfigureAwait(false); } catch (RequestFailedException e) { _viewProvider.ShowMessage(CappuChat.Properties.Strings.Error, e.Message); } }
public HoroscopesCacheAward(ErlArray array) { resultType = StringKit.toInt((array.Value [0] as ErlType).getValueString()); if (resultType == ROLE) { user = new SimpleUser(array.Value [1] as ErlArray); } else if (resultType == NVSHEN) { star = StringKit.toInt((array.Value [1] as ErlType).getValueString()); } awards = new int[4] { StringKit.toInt((array.Value [2] as ErlType).getValueString()), StringKit.toInt((array.Value [3] as ErlType).getValueString()), StringKit.toInt((array.Value [4] as ErlType).getValueString()), StringKit.toInt((array.Value [5] as ErlType).getValueString()) }; }
public void Run() { var chat = new TextChat(); AdminUser a = new AdminUser(chat, "Admin"); SimpleUser u1 = new SimpleUser(chat, "User1"); SimpleUser u2 = new SimpleUser(chat, "User2"); chat.SetAdmin(a); chat.Add(u1); chat.Add(u2); a.Send("Welcome to the chat!"); u1.Send("Hello!"); }
public void RemoveUser(string userID, string deptID) { if (this.DeptInRole(deptID, Role.SuperAdminName)) { List <SimpleUser> adminSimpleUsers = BLLFactory <RoleBLL> .Instance.GetAdminSimpleUsers(); if (adminSimpleUsers.Count == 1) { SimpleUser info = (SimpleUser)adminSimpleUsers[0]; if (userID == info.ID) { throw new Exception("管理员角色至少需要包含一个用户!"); } } } deptDAL.RemoveUser(userID, deptID); }
public override void UpdateDatabaseAfterUpdateSchema() { SimpleUser user = Session.FindObject <SimpleUser>(new BinaryOperator("UserName", "szzz")); if (user == null) { user = new SimpleUser(Session); user.UserName = "******"; user.FullName = "szzz-admin"; } // Make the user an administrator user.IsAdministrator = true; // Set a password if the standard authentication type is used user.SetPassword(""); // Save the user to the database user.Save(); }
private static SimpleUser InitSuperAdmin() { List <IRole> roles = new List <IRole>(); SimpleRole role = new SimpleRole(); role.RoleID = "SUPER_ADMIN"; role.RoleName = "超级管理员"; role.Urls = GetModulesInRole(new Guid("69A61B69-B57F-480A-BCB2-5B71E5BF954A")); roles.Add(role); SimpleUser user = new SimpleUser(); user.LogonID = "SUPER_ADMIN"; user.DisplayName = "超级管理员"; user.Roles = roles; return(user); }
public async Task Insert_row_with_auto_incremet() { var table = new SimpleUserTable(); table.Create(_connection); var expected = new SimpleUser() { FirstName = "Arne" }; await _connection.InsertAsync(expected); var actual = await _connection.FirstAsync <SimpleUser>(new { expected.Id }); actual.FirstName.Should().Be(expected.FirstName); actual.Id.Should().Be(expected.Id); }
public override void UpdateDatabaseAfterUpdateSchema() { SimpleUser user = ObjectSpace.FindObject <SimpleUser>(new BinaryOperator("UserName", "Barkol")); if (user == null) { user = ObjectSpace.CreateObject <SimpleUser>(); user.UserName = "******"; user.FullName = "Barkol2011"; } // Make the user an administrator user.IsAdministrator = true; // Set a password if the standard authentication type is used user.SetPassword(""); // Save the user to the database user.Save(); }
private static List <SimpleUser> DiscoverChanges(Dictionary <string, SimpleUser> codeNameDict, IEnumerable <SearchResult> adResults) { List <SimpleUser> changes = new List <SimpleUser>(); foreach (SearchResult item in adResults) { SimpleUser entity = codeNameDict[(string)item.Properties["sAMAccountName"][0]]; if (IsDifferent(item, entity)) { entity.Tag = item; changes.Add(entity); } } return(changes); }
//[Authorize(Roles = "Administrator, User")] public async Task <ActionResult <User> > PostUser(SimpleUser user) { User u = new User(); u.name = user.name; u.surname = user.surname; u.nickName = user.nickName; u.password = user.password; u.planToWatchMovies = new List <PlanToWatch>(); u.uerLevel = "0"; u.userScores = new List <UserScore>(); _context.Users.Add(u); await _context.SaveChangesAsync(); return(CreatedAtAction("GetUser", new { id = u.id }, user)); }
public void Init() { CultureInfo en = CultureInfo.CreateSpecificCulture("en"); Thread.CurrentThread.CurrentCulture = en; Thread.CurrentThread.CurrentUICulture = en; helper = new FormHelper(); subscription = new Subscription(); months = new Month[] {new Month(1, "January"), new Month(1, "February")}; product = new Product("memory card", 10, (decimal) 12.30); user = new SimpleUser(); contact = new Contact(); HomeController controller = new HomeController(); ControllerContext context = new ControllerContext(); context.PropertyBag.Add("product", product); context.PropertyBag.Add("user", user); context.PropertyBag.Add("roles", new Role[] { new Role(1, "a"), new Role(2, "b"), new Role(3, "c") }); context.PropertyBag.Add("sendemail", true); context.PropertyBag.Add("confirmation", "abc"); context.PropertyBag.Add("fileaccess", FileAccess.Read); context.PropertyBag.Add("subscription", subscription); context.PropertyBag.Add("months", months); context.PropertyBag.Add("contact", contact); workTable = new DataTable("Customers"); DataColumn workCol = workTable.Columns.Add("CustID", typeof(Int32)); workCol.AllowDBNull = false; workCol.Unique = true; workTable.Columns.Add("Name", typeof(String)); DataRow row = workTable.NewRow(); row[0] = 1; row[1] = "chris rocks"; workTable.Rows.Add(row); row = workTable.NewRow(); row[0] = 2; row[1] = "will ferrell"; workTable.Rows.Add(row); helper.SetController(controller, context); }
public async Task <BuildingRule> SaveAsync(SimpleUser user, BuildingRule buildingRule, CancellationToken cancellationToken = default(CancellationToken)) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (buildingRule == null) { throw new ArgumentNullException(nameof(buildingRule)); } //查看楼盘是否存在 if (!Context.Buildings.Any(x => x.Id == buildingRule.Id)) { Buildings buildings = new Buildings() { Id = buildingRule.Id, CreateUser = user.Id, ResidentUser1 = user.Id, CreateTime = DateTime.Now, OrganizationId = user.OrganizationId, ExamineStatus = 0 }; Context.Add(buildings); } //基本信息 if (!Context.BuildingRules.Any(x => x.Id == buildingRule.Id)) { Context.Add(buildingRule); } else { Context.Attach(buildingRule); Context.Update(buildingRule); } try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { } return(buildingRule); }
private async Task SignUser(SimpleUser user) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, user.Email), new Claim("FullName", user.Email) }; if (user.IsAdmin) { claims.Add(new Claim(ClaimTypes.Role, "admin")); } var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { AllowRefresh = true, // Refreshing the authentication session should be allowed. ExpiresUtc = DateTimeOffset.UtcNow.AddDays(30), // The time at which the authentication ticket expires. A // value set here overrides the ExpireTimeSpan option of // CookieAuthenticationOptions set with AddCookie. IsPersistent = true, // Whether the authentication session is persisted across // multiple requests. Required when setting the // ExpireTimeSpan option of CookieAuthenticationOptions // set with AddCookie. Also required when setting // ExpiresUtc. IssuedUtc = DateTimeOffset.UtcNow, // The time at which the authentication ticket was issued. //RedirectUri = <string> // The full path or absolute URI to be used as an http // redirect response value. }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); }
public async Task <IHttpActionResult> Put(PutBalanceRequest putBalanceRequest) { var claimsIdentity = User.Identity as ClaimsIdentity; if (claimsIdentity == null) { return(InternalServerError()); } var fullName = claimsIdentity.GetFullNameFromClaims(); var originator = new SimpleUser { Id = User.Identity.GetUserId(), UserName = User.Identity.GetUserName(), FullName = fullName }; var result = await _balanceControllerService.UpdateBalance(putBalanceRequest.UserId, putBalanceRequest.Amount, originator); // todo location uri return(Created("", result)); }
private static bool IsDifferent(System.DirectoryServices.SearchResult item, SimpleUser entity) { bool same = true; if (item.Properties.Contains("mail") && item.Properties["mail"][0].ToString() != entity.Mail) { same = false; } else { if (item.Properties.Contains("msRTCSIP-PrimaryUserAddress") && item.Properties["msRTCSIP-PrimaryUserAddress"][0].ToString() != entity.Sip) { same = false; } } return(!same); }
public async Task TestPostRegisterAsync_UserDoesNotExist() { var simpleUser = new SimpleUser { Id = Guid.NewGuid(), Username = "******" }; User nullUser = null; userService.Setup(x => x.GetUserByIdAsync(It.IsAny <Guid>())).ReturnsAsync(nullUser); userProvider.Setup(x => x.GetCurrentUser()).Returns(simpleUser); var result = await controller.PostRegisterAsync(); userService.Verify(x => x.GetUserByIdAsync(It.IsAny <Guid>()), Times.Once()); userService.Verify(x => x.Create(It.IsAny <AzureUser>()), Times.Once()); userService.Verify(x => x.SaveChangesAsync(), Times.Once()); }
public IActionResult Login(SimpleUser user) { //https://docs.microsoft.com/ko-kr/aspnet/core/fundamentals/app-state?view=aspnetcore-2. var IdItem = _context.Users.Find(user.Id); var InputPassword = getHash(user.Password); if (InputPassword == IdItem.Password) { // login success var tokenString = BuildToken(user); HttpContext.Session.SetString("Login", tokenString); } else { Console.WriteLine("로그인 실패"); } return(View("~/Views/Home/Index.cshtml")); }
public override bool DeleteUser(string username, bool deleteAllRelatedData) { try { SimpleUser user = CurrentStore.GetUserByName(username); if (user != null) { CurrentStore.Users.Remove(user); return(true); } return(false); } catch { throw; } }
public async Task SaveAsync(SimpleUser user, string buildingId, ShopFacilities shopFacilities, CancellationToken cancellationToken = default(CancellationToken)) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (shopFacilities == null) { throw new ArgumentNullException(nameof(shopFacilities)); } //查看楼盘是否存在 if (!Context.Shops.Any(x => x.Id == shopFacilities.Id)) { Shops shops = new Shops() { Id = shopFacilities.Id, BuildingId = buildingId, CreateUser = user.Id, CreateTime = DateTime.Now, OrganizationId = user.OrganizationId, ExamineStatus = 0 }; Context.Add(shops); } //基本信息 if (!Context.ShopFacilities.Any(x => x.Id == shopFacilities.Id)) { Context.Add(shopFacilities); } else { Context.Attach(shopFacilities); Context.Update(shopFacilities); } try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { } }
public async Task SaveAsync(SimpleUser user, string buildingId, List <AnnexInfo> contractFileScopeList, CancellationToken cancellationToken = default(CancellationToken)) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (contractFileScopeList == null || contractFileScopeList.Count == 0) { return; } foreach (AnnexInfo file in contractFileScopeList) { if (String.IsNullOrEmpty(file.FileGuid)) { file.FileGuid = Guid.NewGuid().ToString("N").ToLower(); } //查看合同是否存在 if (!Context.ContractInfos.Any(x => x.ID == file.ContractID)) { return; } //附件基本信息 if (!Context.AnnexInfos.Any(x => x.ID == file.ID)) { file.CreateTime = DateTime.Now; file.CreateUser = user.Id; Context.Add(file); } else { Context.Attach(file); Context.Update(file); } } try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException e) { throw e; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Does i have a QueryString if (Request.QueryString["id"] != "") { //Load user details SimpleUser objUser = MatrimonialAdministratorMembership.GetAdminAccountDetails(Request.QueryString["id"]); TB_MailAdd.Text = objUser.EmailID; TB_UserID.Text = objUser.MatrimonialID; TB_UserName.Text = objUser.UserName; TB_UserType.Text = objUser.Membership.ToString(); } else { //Some error happend Server.Transfer("~/Extras/ErrorReport.aspx"); } } else//Update Informations { if (CB_Del.Checked) { //Delete Account if (MatrimonialAdministratorMembership.DeleteAdminAccount(TB_UserID.Text)) { L_Error.Visible = true; B_Delete.Visible = false; CB_Del.Visible = false; } else { //Some error happend Server.Transfer("~/Extras/ErrorReport.aspx"); } } else { CB_Del.ForeColor = System.Drawing.Color.Red; } } }
public async Task single_async_returns_first_and_only() { var user1 = new SimpleUser { UserName = "******", Number = 5, Birthdate = new DateTime(1986, 10, 4), Address = new SimpleAddress { HouseNumber = "12bis", Street = "rue de la martre" } }; theSession.Store(user1); await theSession.SaveChangesAsync(); var userJson = await theSession.Query <SimpleUser>().ToJsonSingle(); userJson.ShouldBeSemanticallySameJsonAs($@"{user1.ToJson()}"); }
private static bool IsDifferent(System.DirectoryServices.SearchResult item, SimpleUser entity) { bool same = true; if (item.Properties.Contains("mail") && item.Properties["mail"][0].ToString() != entity.Mail) same = false; else { if (item.Properties.Contains("msRTCSIP-PrimaryUserAddress") && item.Properties["msRTCSIP-PrimaryUserAddress"][0].ToString() != entity.Sip) same = false; } return !same; }
public async Task<IdentityResult> CreateAsync(SimpleUser user) { var result = await _userManager.CreateAsync(user); return result; }
public List<SimpleUser> SimplySearchUser(SearchUserDTO dto) { List<SimpleUser> list=new List<SimpleUser>(); SimpleUser sUser; try { SqlDataReader reader = ConnectionManager.GetCommand("sp0002simple", new Dictionary<string, SqlDbType>() { {"@userName", SqlDbType.NVarChar}, }, new List<object>() { dto.UserName }).ExecuteReader(); while (reader.Read()) { sUser=new SimpleUser(); sUser.UserID = reader["UserID"].ToString(); sUser.Username = reader["Username"].ToString(); list.Add(sUser); } reader.Close(); } catch (Exception e) { Log.Error("Error at AuthorDAO - GetAuthorByID", e); return null; } return list; }