Exemplo n.º 1
0
        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");
                }
            }
        }
Exemplo n.º 2
0
        public override async Task SignOutAsync()
        {
            var sessionInfo = idInfo_.GetSessionInfo();
            await sessionRepository_.Value.DeleteSession(sessionInfo);

            await base.SignOutAsync();
        }
Exemplo n.º 3
0
        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");
                }
            }
        }
Exemplo n.º 4
0
        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)));
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        // 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));
        }
Exemplo n.º 7
0
        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());
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 10
0
        //[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());
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        public ActionResult <int> WhoAmI1()
        {
            var sessionInfo = idInfo_.GetSessionInfo();

            return(sessionInfo.AccountId);
        }
Exemplo n.º 13
0
        public Task <string> CreatePersistentToken()
        {
            var sessionInfo = idInfo_.GetSessionInfo();

            return(persistentTokenRepository_.Value.CreatePersistentToken(sessionInfo.AccountId));
        }