public async Task SendFeedback(FeedbackParameters feedbackParameters) { SessionInfo sessionInfo = idInfoAccessor_.GetSessionInfo(); var applicationUser = await accountRepository_.Value.FindUserByAccountIdAsync(sessionInfo.AccountId); var emailMessage = new EmailMessage(); emailMessage.FromName = applicationUser.UserName; emailMessage.FromEmail = "*****@*****.**"; emailMessage.To = new[] { new EmailAddress(feedbackEmailAddress_) }; emailMessage.Text = $"User Email: {applicationUser.Email}\n\n{JavaScriptEncoder.Default.Encode(HtmlEncoder.Default.Encode(feedbackParameters.Feedback))}"; var messageRequest = new SendMessageRequest(emailMessage); List <EmailResult> emailResults = await mandrillApi_.SendMessage(messageRequest); foreach (var item in emailResults) { if (item.Status == EmailResultStatus.Rejected) { throw new ServerErrorException($"Sending email to {item.Email} failed with reason: {item.RejectReason}"); } if (item.Status == EmailResultStatus.Invalid) { throw new InvalidArgumentException($"Sending email to {item.Email} is invalid"); } } }
public override async Task SignOutAsync() { var sessionInfo = idInfo_.GetSessionInfo(); await sessionRepository_.Value.DeleteSession(sessionInfo); await base.SignOutAsync(); }
public async Task <FeatureDetail> CreateFeature(string name, FeatureUpdateParams prms) { var sessionInfo = idInfo_.GetSessionInfo(); if (!sessionInfo.IsUser) { throw new AccessDeniedException($"Login required"); } if (newGates_) { var entry = new FeatureEntry() { Name = name, Issuer = sessionInfo.AccountId, Disabled = true, }; entry.Update(prms); try { var tableResult = await featureStore_.Value.Storage.ExecuteAsync(Microsoft.Azure.Cosmos.Table.TableOperation.Insert(entry.To <FeatureEntryTableEntity>())); var newEntry = (FeatureEntryTableEntity)tableResult.Result; return(newEntry.To <FeatureEntry>().ToFeatureDetail()); } catch (Microsoft.Azure.Cosmos.Table.StorageException e) when(e.RequestInformation.HttpStatusCode == 409) { throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to create feature, already created"); } } else { var entry = new LegacyFeatureEntry() { PartitionKey = FeatureGateStore.GatePartitionKey, Name = name, Issuer = sessionInfo.AccountId, Disabled = true, }; entry.Update(prms); try { TableResult tableResult = await featureStore_.Value.GatesTable.Table.ExecuteAsync(TableOperation.Insert(entry)); var newEntry = (LegacyFeatureEntry)tableResult.Result; return(newEntry.ToFeatureDetail()); } catch (StorageException e) when(e.RequestInformation.HttpStatusCode == 409) { throw new HttpStatusErrorException(HttpStatusCode.Conflict, $"Faild to create feature, already created"); } } }
public Task CreateRoleAsync(string role) { var sessionInfo = idInfo_.GetSessionInfo(); if (!sessionInfo.IsUser) { throw new AccessDeniedException("Login required"); } if (!sessionInfo.Roles.Contains(UserRoles.UserAdmin)) { throw new AccessDeniedException("Insufficient roles"); } if (UserRoles.PhantomRoles.Contains(role)) { throw new InvalidArgumentException($"phantom role cannot be created: {role}"); } return(roleManager_.CreateAsync(new IdentityRole(role))); }
public async Task <ActionResult> RefreshSession() { SiteInfo siteInfo = await Request.HttpContext.GetSiteInfo(); var sessionInfo = idInfo_.GetSessionInfo(); await signInManager_.SignInAsync(sessionInfo.AccountId, true, CredentialType.RefreshKey.ToString()); return(Ok()); }
// Consider deprecate in favor of /iam/api/v1/email/owned/status public Task <bool> GetEmailConfirmed( [FromServices] ICreyService <AccountRepository> accounts, [FromServices] IIDInfoAccessor idInfo ) { var sessionInfo = idInfo.GetSessionInfo(); return(accounts.Value.GetEmailConfirmedStatusAsync(sessionInfo.AccountId)); }
public async Task <ActionResult> SetEmailStatusAsync(PatchEmailStatus param, [FromServices] ICreyService <AccountRepository> accounts, [FromServices] IIDInfoAccessor idInfo, [FromServices] CreyRestClient creyRestClient) { var sessionInfo = idInfo.GetSessionInfo(); await accounts.Value.SetEmailStatusAsync(sessionInfo.AccountId, param); return(Ok()); }
public async Task <EmailStatus> GetEmailStatus( [FromServices] ICreyService <AccountRepository> accounts, [FromServices] IIDInfoAccessor idInfo, [FromServices] CreyRestClient creyRestClient) { var sessionInfo = idInfo.GetSessionInfo(); var status = await accounts.Value.GetEmailStatusAsync(sessionInfo.AccountId); return(status); }
public async Task <ActionResult <string> > CreateToken() { var info = idInfo_.GetSessionInfo(); if (!info.IsUser) { throw new Crey.Exceptions.AccessDeniedException($"Login required"); } var token = await singleAccesKey_.Value.CreateKey(info.AccountId); return(HttpUtility.UrlEncode(token)); }
//[ServerToServer] public async Task <SessionInfo> SignInWithAccountIdAsync( int accountId, [FromServices] ICreyService <AccountRepository> db, [FromServices] SignInManager <ApplicationUser> signIn, [FromServices] IIDInfoAccessor idInfo) { var user = await db.Value.FindUserByAccountIdAsync(accountId); await signIn.SignInAsync(user, false, CredentialType.Impersonation.ToString()); // note: also session is passed in cookies, still simplify code with returning it directly // and in future seems it will be resonable somehow create `session` without setting cookies return(idInfo.GetSessionInfo()); }
public void TrackEvent(string category, string action, string label = "", string value = "") { var cookieCollection = httpContextAccessor_.HttpContext.Request.Cookies; string cliendId = "555"; // Anonymous Client ID. https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide string gaCookie = ""; if (cookieCollection.TryGetValue("_ga", out gaCookie)) { cliendId = gaCookie.Substring(6); } string userId = ""; var sessionInfo = idInfoAccessor_.GetSessionInfo(); if (sessionInfo.IsValid) { userId = sessionInfo.AccountId.ToString(); } else { string trackingId = ""; if (cookieCollection.TryGetValue(configuration_.GetTrackingIdCookieName(), out trackingId)) { userId = trackingId; } } var input = new Dictionary <string, string> { { "v", "1" }, { "tid", configuration_.GetGoogleAnalyticsTrackingId(sessionInfo) }, { "cid", cliendId }, { "uid", userId }, { "time", DateTime.Now.ToIsoString() }, { "t", "event" }, { "ec", category }, { "ea", action }, { "el", label }, { "ev", value }, }; PostToGoogle(input); PostToCrey(input); }
public ActionResult <int> WhoAmI1() { var sessionInfo = idInfo_.GetSessionInfo(); return(sessionInfo.AccountId); }
public Task <string> CreatePersistentToken() { var sessionInfo = idInfo_.GetSessionInfo(); return(persistentTokenRepository_.Value.CreatePersistentToken(sessionInfo.AccountId)); }