public void WhenUserIsNull_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => { UserExtensions.ToMailAddress(null); }); }
public void WhenUserIsNull_ThrowsArgumentNullException() { Assert.Throws <ArgumentNullException>(() => { UserExtensions.IsOwnerOrMemberOfOrganizationOwner(null, new PackageRegistration()); }); }
public ActionResult _MergeTag() { TagViewModel viewModel = new TagViewModel(); GetTagListResponse response = tagService.GetTagsBasedonaccount(UserExtensions.ToAccountID(this.Identity)); viewModel.Tags = response.Tags; return(PartialView("_MergeTag", viewModel)); }
public string[] GetCompletionList(string prefixText, int count) { if (count == 0) { count = 10; } return(UserExtensions.GetUsersByName(prefixText).ToArray()); }
public void EscapeStringlistReturnsEmptyStringforEmptyLists() { Assert.AreEqual("", UserExtensions.StringlistToEscapedStringForEnvVar(new List <string> { "" })); Assert.AreEqual("", UserExtensions.StringlistToEscapedStringForEnvVar(new List <string>())); Assert.AreEqual("", UserExtensions.StringlistToEscapedStringForEnvVar(Enumerable.Empty <string>())); }
public MatchmakingData GetExistingLobbyInfo() { if (this.User.Identity.IsAuthenticated) { var steamId = UserExtensions.GetSteamId(this.User); return(_matchmakingService.GetExistingLobbyInfo(steamId)); } return(null); }
public LobbyInfo GetLobbyInfo([FromBody] int eventId) { if (this.User.Identity.IsAuthenticated) { var steamId = UserExtensions.GetSteamId(this.User); return(_schedulingService.GetLobbyInfo(eventId, steamId)); } return(null); }
/// <summary> /// Performs a permissions check for the user to check if it has access to the node based on /// start node and/or permissions for the node /// </summary> /// <param name="storage">The storage to add the content item to so it can be reused</param> /// <param name="user"></param> /// <param name="userService"></param> /// <param name="contentService"></param> /// <param name="nodeId">The content to lookup, if the contentItem is not specified</param> /// <param name="permissionsToCheck"></param> /// <param name="contentItem">Specifies the already resolved content item to check against</param> /// <returns></returns> internal static bool CheckPermissions( IDictionary <string, object> storage, IUser user, IUserService userService, IContentService contentService, int nodeId, char[] permissionsToCheck = null, IContent contentItem = null) { if (contentItem == null && nodeId != Constants.System.Root && nodeId != Constants.System.RecycleBinContent) { contentItem = contentService.GetById(nodeId); //put the content item into storage so it can be retreived // in the controller (saves a lookup) storage[typeof(IContent).ToString()] = contentItem; } if (contentItem == null && nodeId != Constants.System.Root && nodeId != Constants.System.RecycleBinContent) { throw new HttpResponseException(HttpStatusCode.NotFound); } var hasPathAccess = (nodeId == Constants.System.Root) ? UserExtensions.HasPathAccess( Constants.System.Root.ToInvariantString(), user.StartContentId, Constants.System.RecycleBinContent) : (nodeId == Constants.System.RecycleBinContent) ? UserExtensions.HasPathAccess( Constants.System.RecycleBinContent.ToInvariantString(), user.StartContentId, Constants.System.RecycleBinContent) : user.HasPathAccess(contentItem); if (hasPathAccess == false) { return(false); } if (permissionsToCheck == null || permissionsToCheck.Any() == false) { return(true); } var permission = userService.GetPermissions(user, nodeId).FirstOrDefault(); var allowed = true; foreach (var p in permissionsToCheck) { if (permission == null || permission.AssignedPermissions.Contains(p.ToString(CultureInfo.InvariantCulture)) == false) { allowed = false; } } return(allowed); }
public bool IsQueued() { if (this.User.Identity.IsAuthenticated) { var steamId = UserExtensions.GetSteamId(this.User); return(_matchmakingService.GetIsQueued(steamId)); } return(false); }
public void CombineStartNodes(string groupSn, string userSn, string expected) { // 1 // 3 // 5 // 2 // 4 // bin // 6 // 7 // 8 var paths = new Dictionary <int, string> { { 1, "-1,1" }, { 2, "-1,2" }, { 3, "-1,1,3" }, { 4, "-1,2,4" }, { 5, "-1,1,3,5" }, { 6, "-1,-20,6" }, { 7, "-1,-20,7" }, { 8, "-1,-20,7,8" }, }; var esmock = new Mock <IEntityService>(); esmock .Setup(x => x.GetAllPaths(It.IsAny <UmbracoObjectTypes>(), It.IsAny <int[]>())) .Returns <UmbracoObjectTypes, int[]>((type, ids) => paths.Where(x => ids.Contains(x.Key)).Select(x => new TreeEntityPath { Id = x.Key, Path = x.Value })); var comma = new[] { ',' }; var groupSnA = groupSn.Split(comma, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray(); var userSnA = userSn.Split(comma, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x, CultureInfo.InvariantCulture)).ToArray(); var combinedA = UserExtensions.CombineStartNodes(UmbracoObjectTypes.Document, groupSnA, userSnA, esmock.Object) .OrderBy(x => x).ToArray(); var expectedA = expected.Split(comma, StringSplitOptions.RemoveEmptyEntries) .Select(x => int.Parse(x, CultureInfo.InvariantCulture)).OrderBy(x => x).ToArray(); var ok = combinedA.Length == expectedA.Length; if (ok) { ok = expectedA.Where((t, i) => t != combinedA[i]).Any() == false; } if (ok == false) { Assert.Fail("Expected \"" + string.Join(",", expectedA) + "\" but got \"" + string.Join(",", combinedA) + "\"."); } }
public static async Task <RaidCreateConversation> Create(ConversationService conversationService, RaidService raidService, UserService userService, IUser user, IGuild guild, int frequency) { string sendMessage = "Raid Setup:\n" + "You can type \"cancel\" at any point during this process to cancel the raid setup\n\n" + "Enter the name for raid run:"; await UserExtensions.SendMessageAsync(user, sendMessage); //Create Conversation return(new RaidCreateConversation(conversationService, raidService, userService, user, guild, frequency)); }
public ActionResult GetSeedList() { int RoleId = UserExtensions.ToRoleID(this.Identity); GetSeedListResponse response = seedListService.GetSeedList(new GetSeedListRquest() { RequestedBy = RoleId }); return(View("SeedList", response.SeedEmailViewModel)); }
public override Task OnConnectedAsync() { if (Context.User.Identity.IsAuthenticated) { var steamId = UserExtensions.GetSteamId(Context.User); UserConnections.Add(steamId, Context.ConnectionId); } return(base.OnConnectedAsync()); }
private static bool IsPasswordMatch(UserCredentials userCredentials, string suppliedPassword) { var databaseHashedUserPassword = Convert.FromBase64String(userCredentials.PasswordHash); var databaseUserSalt = Convert.FromBase64String(userCredentials.PasswordSalt); var providedPasswordHash = UserExtensions.HashPassword(Encoding.UTF8.GetBytes(suppliedPassword), databaseUserSalt, userCredentials.HashIterations); return(UserExtensions.PasswordHashesEqual(databaseHashedUserPassword, providedPasswordHash)); }
public static async Task <AccountSwitchConversation> Create(ConversationService conversationService, UserService userService, IUser user, ulong guildId) { string message = "Which account should be your main account?"; message += $"\n{userService.PrintAccounts(guildId, user.Id)}"; message += "\n\ntype cancel to cancel the interaction."; await UserExtensions.SendMessageAsync(user, message); return(new AccountSwitchConversation(conversationService, userService, user, guildId)); }
public override Task OnDisconnectedAsync(Exception ex) { if (Context.User.Identity.IsAuthenticated) { var steamId = UserExtensions.GetSteamId(Context.User); UserConnections.Remove(steamId, Context.ConnectionId); } return(base.OnDisconnectedAsync(ex)); }
public IActionResult DeleteEvent([FromBody] int id) { if (this.User.Identity.IsAuthenticated) { var steamId = UserExtensions.GetSteamId(this.User); _schedulingService.DeleteEvent(steamId, id); return(Ok()); } return(Unauthorized()); }
private async Task <bool> SetVoiceChatAsync(string message) { if (message == null) { await UserExtensions.SendMessageAsync(_user, $"No voice chat was found."); return(false); } _raid.VoiceChat = message; return(true); }
private async Task <bool> SetOrganisatorAsync(string message) { if (message == null) { await UserExtensions.SendMessageAsync(_user, $"No organisator was found."); return(false); } _raid.Organisator = message; return(true); }
private async Task <bool> SetGuildAsync(string message) { if (message == null) { await UserExtensions.SendMessageAsync(_user, $"No guild was found."); return(false); } _raid.Guild = message; return(true); }
public async Task ProcessMessage(string message) { if (message.Equals("cancel", StringComparison.OrdinalIgnoreCase)) { await UserExtensions.SendMessageAsync(_user, "interaction canceled"); _conversationService.CloseConversation(_user.Id); return; } await ProcessUncanceledMessage(message); }
public static string Culture(User u) { if (ApplicationContext.Current == null) { return(string.Empty); } var found = UserExtensions.GetUserCulture(u.Language, ApplicationContext.Current.Services.TextService); return(found == null ? string.Empty : found.Name); }
public ActionResult GetList() { int RoleId = UserExtensions.ToRoleID(this.Identity); GetSeedListResponse response = seedListService.GetSeedList(new GetSeedListRquest() { RequestedBy = RoleId }); var data = response.SeedEmailViewModel; return(Json(new { success = true, response = data }, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteRule(string leadScoreData) { DeleteLeadScoreRequest request = JsonConvert.DeserializeObject <DeleteLeadScoreRequest>(leadScoreData); request.accountID = UserExtensions.ToAccountID(this.Identity); leadScoreService.UpdateLeadScoreStatus(request); return(Json(new { success = true, response = "" }, JsonRequestBehavior.AllowGet)); }
public ActionResult LeadAdapterList() { LeadAdapterViewModel viewModel = new LeadAdapterViewModel(); viewModel.AccountID = UserExtensions.ToAccountID(this.Identity); short ItemsPerPage = default(short); short.TryParse(this.Identity.ToItemsPerPage(), out ItemsPerPage); ViewBag.ItemsPerPage = ItemsPerPage; ViewBag.DateFormat = this.Identity.ToDateFormat(); return(View("LeadAdapterList", viewModel)); }
public IActionResult SendMessage([FromBody] ChatMessage message) { if (this.User.Identity.IsAuthenticated) { var steamId = UserExtensions.GetSteamId(this.User); message.SteamId = steamId; message.Sent = DateTime.Now; _schedulingService.AddMessage(message); return(Ok()); } return(Unauthorized()); }
public async Task <IActionResult> Google([FromBody] GoogleModel googleModel) { var appAccessToken = new AppAccessToken(); var tokenResponse = await Client.PostAsync($"https://www.googleapis.com/oauth2/v4/token?code={googleModel.Code}&client_id={_googleAuthModel.ClientId}&client_secret={_googleAuthModel.ClientSecret}&redirect_uri=http://localhost/oauth2callback&grant_type=authorization_code", null); if (tokenResponse.StatusCode != HttpStatusCode.OK) { return(new BadRequestObjectResult(new { code = "InvalidCode", description = tokenResponse.Content.ReadAsStringAsync().Result }));// "Google authorization code is not valid."}); } appAccessToken = JsonConvert.DeserializeObject <AppAccessToken>(tokenResponse.Content.ReadAsStringAsync().Result); var userResponse = await Client.GetStringAsync($"https://www.googleapis.com/oauth2/v2/userinfo?access_token={appAccessToken.AccessToken}"); var userInfo = JsonConvert.DeserializeObject <GoogleUserData>(userResponse); var existingUser = await _userManager.FindByEmailAsync(userInfo.Email); if (existingUser == null) { var user = new ApplicationUser { GoogleId = userInfo.Id, Email = userInfo.Email, UserName = userInfo.FirstName + userInfo.LastName, PictureUrl = userInfo.Picture, Visibility = true, Nationality = "US" }; if (userInfo.Gender != null) { user.Gender = userInfo.Gender.Equals("male") ? Gender.Male : userInfo.Gender.Equals("female") ? Gender.Female : Gender.Other; } else { user.Gender = Gender.None; } user.UserName = UserExtensions.RemoveDiacritics(user.UserName); var result = await _userManager.CreateAsync(user, Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring(0, 8)); if (!result.Succeeded) { return(new BadRequestObjectResult(result.Errors)); } else { existingUser = await _userManager.FindByNameAsync(user.UserName); } } var jwt = await Tokens.GenerateJwt(_jwtFactory.GenerateClaimsIdentity(existingUser.UserName, existingUser.Id), _jwtFactory, existingUser.UserName, _jwtOptions, new JsonSerializerSettings { Formatting = Formatting.Indented }, existingUser.ProfileComplete); return(new OkObjectResult(jwt)); }
public JsonResult InsertSeedList(string SeedEmail) { int userID = UserExtensions.ToUserID(this.Identity); IEnumerable <SeedEmailViewModel> viewModel = JsonConvert.DeserializeObject <IEnumerable <SeedEmailViewModel> >(SeedEmail); InsertSeedListResponse response = seedListService.InsertSeedList(new InsertSeedListRequest() { RequestedBy = userID, SeedEmailViewModel = viewModel }); return(Json(new { success = true, response = response }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Converts a list of Users into a csv file. /// </summary> /// <param name="users">A list of Users you want to convert.</param> /// <returns>Returns a csv file as a byte array.</returns> public static byte[] ExportToCSV(IEnumerable <User> users) { StringBuilder sb = new StringBuilder(); sb.AppendLine(UserExtensions.GetCsvHeader()); foreach (User u in users) { sb.AppendLine(u.ToCsv()); } return(Encoding.ASCII.GetBytes(sb.ToString())); }
public ScrimEventViewModel AddEvent([FromBody] ScrimEvent scrimEvent) { if (this.User.Identity.IsAuthenticated) { var steamId = UserExtensions.GetSteamId(this.User); scrimEvent.SteamId = steamId; var newEvent = _schedulingService.AddEvent(scrimEvent); var newEventViewModel = this.GetEventViewModel(newEvent); _schedulingService.NotifyEventAdded(newEventViewModel); return(newEventViewModel); } return(null); }
public void SugarNurse(HttpContext Context) { string mobile = Context.Request.QueryString["mobile"]; string time = Context.Request.QueryString["time"]; string phase = Context.Request.QueryString["phase"]; decimal? value =Convert.ToDecimal(Context.Request.QueryString["value"]); object obj = null; string errorMsg = String.Empty; //出错消息 string Msg = String.Empty; //消息 bool success = true; //是否成功 bool openflag = true; List<object> list = new List<object>(); #region 验证参数 if (mobile == null || mobile == "") { success = false; Msg = "mobile:参数不能为空!"; } if (time == null || time == "") { success = false; Msg = "time:参数不能为空!"; } if (phase == null || phase == "") { success = false; Msg = "phase:参数不能为空!"; } if (value == null) { success = false; Msg = "value:参数不能为空!"; } #endregion if (success) { try { string stactTime = "1970-1-1 00:00:00"; DateTime dataTime= Convert.ToDateTime(stactTime).AddSeconds(Convert.ToDouble(time)); UserExtensions userExtensionsModel = new UserExtensions() { mobile = mobile, time = Convert.ToDateTime(dataTime), phase = Convert.ToInt32(phase), value = value }; var id=Daxu.BLL.UserExtensionsBll.InsertEntity<UserExtensions>(userExtensionsModel); if (id < 0) { Msg = "数据插入失败!"; } else { success = true; Msg = "ok"; //向前台推送消息 Chat send = new Chat(); send.SendMobileUser(userExtensionsModel.mobile); } } catch(Exception ex) { success = false; Msg = ex.Message; } } obj = new { success = success, Message =Msg }; Context.Response.ContentType = "text/html; charset=utf-8"; Context.Response.Write(Msg); Context.Response.End(); }