Esempio n. 1
0
        public async Task <IHttpActionResult> Register(RegisterViewModel model)
        {
            try
            {
                var accountsDetail = new ViewAccountDetails();
                accountsDetail = Mapper.Map(model, accountsDetail);

                var acceptLanguage = Request.Headers.AcceptLanguage.FirstOrDefault();
                if (!object.Equals(acceptLanguage, null) && !string.IsNullOrEmpty(acceptLanguage.Value))
                {
                    accountsDetail.LanguageISO2 = acceptLanguage.Value.Substring(0, 2).ToLower();
                }

                _b2blead(model);

                if (!object.Equals(model.Params, null))
                {
                    accountsDetail.Cmp     = model.Params.Cmp;
                    accountsDetail.Partner = model.Params.Partner;
                    accountsDetail.Build   = model.Params.Build;
                    accountsDetail.Uid     = model.Params.GetUid();
                }

                var account = await _auth.AccountGetAsync(model.Email);

                if (object.Equals(account, null))
                {
                    account = await _auth.AccountGetAsync(model.Email, isIncludeSubEmails : true);

                    if (!object.Equals(account, null))
                    {
                        return(AccountExists());
                    }
                }
                else if (account.IsEmptyPassword())
                {
                    var sessionTokensExternalHistory = await _auth.SessionTokenExternalHistoriesAsync(account.Id);

                    var sessionTokenExternalHistory = sessionTokensExternalHistory.FirstOrDefault(e => !e.IsUnlinked);
                    if (!object.Equals(sessionTokenExternalHistory, null))
                    {
                        return(ErrorContent("invalid_grant", string.Format("You should sign in with {0}.", sessionTokenExternalHistory.ExternalClientName), System.Net.HttpStatusCode.Conflict));
                    }
                }

                if ("soda pdf 8".Equals(model.Source, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(await _registerLegal(model, account, accountsDetail));
                }

                return(await _register(model, account, accountsDetail, "register"));
            }
            catch (Exception exc) { return(Request.HttpExceptionResult(exc)); }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Details(AccountDetailsViewModel model)
        {
            try
            {
                var accountsDetail = new ViewAccountDetails();
                accountsDetail    = Mapper.Map(model, accountsDetail);
                accountsDetail.Id = AccountId;

                accountsDetail.GeoIp = IpAddressDetector.IpAddress;
                await _auth.AccountDetailsSetAsync(accountsDetail);
            }
            catch (Exception exc) { return(Request.HttpExceptionResult(exc)); }

            return(Ok());
        }
        internal async Task AccountDetailsSetAsync(ViewAccountDetails accountDetails)
        {
            var sqlParams = new List <SqlParameter>
            {
                accountDetails.Id.ToSql("accountId"),
                accountDetails.FirstName.ToSql("firstName"),
                accountDetails.LastName.ToSql("lastName"),
                accountDetails.Phone.ToSql("phone"),
                accountDetails.PhoneESign.ToSql("phoneESign"),
                accountDetails.Company.ToSql("company"),
                accountDetails.Occupation.ToSql("occupation"),
                accountDetails.CountryISO2.ToSql("countryISO2"),
                accountDetails.LanguageISO2.ToSql("languageISO2"),
                accountDetails.Address1.ToSql("address1"),
                accountDetails.Address2.ToSql("address2"),
                accountDetails.City.ToSql("city"),
                accountDetails.State.ToSql("state"),
                accountDetails.PostalCode.ToSql("postalCode"),
                accountDetails.Build.ToSql("build"),
                accountDetails.Cmp.ToSql("cmp"),
                accountDetails.Uid.ToSql("uid"),
                accountDetails.GeoIp.ToSql("geoIP"),
                accountDetails.Source.ToSql("source"),
                accountDetails.Optin.ToSql("optin"),
                accountDetails.WebForm.ToSql("webForm"),
                accountDetails.Partner.ToSql("partner")
                //accountDetails.InstallationID.ToSql("installationID")
                //accountDetails.IsTrial.ToSql("isTrial")
            };

            //Warning! All transmitted parameters must be implemented on the DB side in this procedure of appropriate product.
#if LuluSoft
            sqlParams.Add(accountDetails.IsTrial.ToSql("trialDays"));
            sqlParams.Add(accountDetails.IsTrial.ToSql("isTrial"));
            sqlParams.Add(accountDetails.InstallationID.ToSql("installationID"));
#endif
            await ExecuteNonQueryAsync("[accounts].[pAccountDetailSetByAccountID]", sqlParams);
        }
Esempio n. 4
0
        public async Task <IHttpActionResult> Details(Guid userId, AccountDetailsViewModel model)
        {
            try
            {
                var account = await _auth.AccountGetAsync(userId);

                if (object.Equals(account, null))
                {
                    return(AccountNotFound());
                }

                var accountsDetail = new ViewAccountDetails();
                accountsDetail = Mapper.Map(model, accountsDetail);

                accountsDetail.GeoIp = IpAddressDetector.IpAddress;
                accountsDetail.Id    = account.Id;

                await _auth.AccountDetailsSetAsync(accountsDetail);
            }
            catch (Exception exc) { return(Request.HttpExceptionResult(exc)); }

            return(Ok());
        }
Esempio n. 5
0
        internal static void CreateAccountWarn(HttpRequestMessage request, Account account, ViewAccountDetails details, string stackTrace)
        {
            //string message = null;

            //if (object.Equals(details, null))
            //    message = "ViewAccountDetails is null.";

            //if (!object.Equals(details, null) && !details.Uid.HasValue)
            //    message = "ViewAccountDetails.Uid is null.";

            //if (!object.Equals(message, null))
            //{
            //    var referrer = string.Empty;
            //    if (!object.Equals(request.Headers, null) && !object.Equals(request.Headers.Referrer, null))
            //        referrer = request.Headers.Referrer.ToString();

            //    var source = string.Empty;
            //    if (!object.Equals(details, null))
            //        source = details.Source;

            //    var builder = new StringBuilder();
            //    builder.AppendLine(message);
            //    builder.AppendLine(string.Format("AccountId: {0}", account.Id));
            //    builder.AppendLine(string.Format("Referrer: {0}", referrer));
            //    builder.AppendLine(string.Format("Stack trace: {0}", stackTrace));
            //    builder.AppendLine(string.Format("Source: {0}", source));

            //    _oauthCreateAccountLogger.Warn(builder.ToString());
            //}
        }
Esempio n. 6
0
        public async Task <IHttpActionResult> Token(SignInViewModel internalSignInViewModel, CancellationToken cancellationToken)
        {
            var task = GetExternalToken(internalSignInViewModel.State, cancellationToken);

            if (task.Status == TaskStatus.WaitingForActivation || object.Equals(task.Result, null) || object.Equals(task.Result.Token, null))
            {
                return(ResponseMessage(new HttpResponseMessage(HttpStatusCode.PartialContent)));
            }

            var token = task.Result;

            internalSignInViewModel.ExternalClient = token.Provider;

            var service = OauthServiceFactory.CreateService(token.Provider);
            var profile = await service.ProfileAsync(token.Token, cancellationToken);

            var account = await _auth.AccountGetAsync(profile.Email, isIncludeSubEmails : true);

            if (!object.Equals(account, null))
            {
                var sessionTokens = await _auth.SessionTokenExternalHistoriesAsync(account.Id);

                if (sessionTokens.Any(e => e.IsUnlinked &&
                                      string.Equals(token.Provider, e.ExternalClientName, StringComparison.InvariantCultureIgnoreCase) &&
                                      string.Equals(profile.Id, e.ExternalAccountId, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(AccountIsDisconnected(token.Provider));
                }
            }

            if (object.Equals(account, null))
            {
                account = new Account(profile.Email, profile.FirstName, profile.LastName);

                var result = await _auth.AccountCreateAsync(account);

                var errorResult = GetErrorResult(result);

                if (!object.Equals(errorResult, null))
                {
                    return(errorResult);
                }

                var accountsDetail = new ViewAccountDetails();
                accountsDetail.GeoIp   = IpAddressDetector.IpAddress;
                accountsDetail.Id      = account.Id;
                accountsDetail.Uid     = token.Uid;
                accountsDetail.Cmp     = token.Cmp;
                accountsDetail.Source  = token.Source;
                accountsDetail.WebForm = token.FormId;
                accountsDetail.Build   = token.Build;
                accountsDetail.Partner = token.Partner;
                accountsDetail.IsTrial = token.Trial;

                await _auth.AccountDetailsSetAsync(accountsDetail);

                await NotificationManager.Welcome(account);
            }

            await _auth.AccountOptinSetAsync(account, token.Optin);

            await _auth.AccountActivateAsync(account);

            internalSignInViewModel.SetUser(account);

            await _auth.SessionTokenExternalHistorySetAsync(account.Id, token.Provider, profile.Id, profile.Email);

            return(ResponseMessage(await OauthManager.InternalSignIn(internalSignInViewModel, token.VisitorId)));
        }
Esempio n. 7
0
        private async Task <IHttpActionResult> _register(RegisterViewModel model, Account account, ViewAccountDetails accountDetails, string stackTrace)
        {
            if (!object.Equals(account, null))
            {
                await _auth.AccountVisitorIdSetAsync(account, model.VisitorId);

                if (model.IsBusiness())
                {
                    await _auth.AccountMaskAsBusinessAsync(account);

                    //make sure that user will get b2b 30 trial
                    await _auth.AccountActivateAsync(account);
                }

                if (account.IsBusiness && string.Equals(model.Source, "sodapdf.com-get-trial", StringComparison.InvariantCultureIgnoreCase))
                {
                    await NotificationManager.BusinessDownload(account);
                }

                if (account.IsEmptyPassword())
                {
                    if (!string.IsNullOrEmpty(model.Password))
                    {
                        await _auth.AccountPasswordSetAsync(account, model.Password);

                        await NotificationManager.AccountCreationComplete(account);
                    }
                    accountDetails.GeoIp = IpAddressDetector.IpAddress;
                    accountDetails.Id    = account.Id;
                    await _auth.AccountDetailsSetAsync(accountDetails);

                    return(Ok());
                }

                return(AccountExists());
            }
            account            = new Account(model.Email, model.FirstName, model.LastName);
            account.IsBusiness = model.IsBusiness();

            var result = await _auth.AccountCreateAsync(account, model.Password);

            var errorResult = GetErrorResult(result);

            if (!object.Equals(errorResult, null))
            {
                return(errorResult);
            }

            accountDetails.GeoIp   = IpAddressDetector.IpAddress;
            accountDetails.Id      = account.Id;
            accountDetails.Source  = model.Source;
            accountDetails.WebForm = FormIdBuilder.Build(model.FormId);

            await _auth.AccountOptinSetAsync(account, model.Optin);

            await _auth.AccountDetailsSetAsync(accountDetails);

            await _auth.AccountVisitorIdSetAsync(account, model.VisitorId);

            OauthLogger.CreateAccountWarn(Request, account, accountDetails, stackTrace);

            if ("sodapdf.com-esign-lite".Equals(model.Source, StringComparison.InvariantCultureIgnoreCase))
            {
                return(Ok()); //
            }
            if (account.IsBusiness && "sodapdf.com-get-trial".Equals(model.Source, StringComparison.InvariantCultureIgnoreCase))
            {
                await NotificationManager.BusinessDownloadNewAccount(account);
            }
            else
            {
                if (!string.IsNullOrEmpty(model.Password))
                {
#if PdfForge
                    if (!object.Equals(accountDetails, null) && "covermount".Equals(accountDetails.Build, StringComparison.InvariantCultureIgnoreCase))
                    {
                        await NotificationManager.EmailConfirmationCovermount(account);

                        return(Ok());
                    }
#endif

                    await NotificationManager.EmailConfirmation(account);
                }
                else
                {
                    if ("sodapdf.com-opdfs".Equals(model.Source, StringComparison.InvariantCultureIgnoreCase) ||
                        "sodapdf.com-opdfs-send-to-email".Equals(model.Source, StringComparison.InvariantCultureIgnoreCase))
                    {
                        await NotificationManager.MicrotransactionCreatePassword(account);
                    }
                }
            }

            return(Ok());
        }
Esempio n. 8
0
        private async Task <IHttpActionResult> _registerLegal(RegisterViewModel model, Account account, ViewAccountDetails accountDetails)
        {
            if (!object.Equals(account, null))
            {
                await _auth.AccountVisitorIdSetAsync(account, model.VisitorId);

                if (account.IsActivated)
                {
                    await NotificationManager.LegacyActivationSignInNotification(account);
                }
                else
                {
                    await NotificationManager.LegacyCreatePasswordReminder(account);
                }

                return(AccountExists());
            }

            account            = new Account(model.Email, model.FirstName, model.LastName);
            account.IsBusiness = model.IsBusiness();

            var result = await _auth.AccountCreateAsync(account, model.Password);

            var errorResult = GetErrorResult(result);

            if (!object.Equals(errorResult, null))
            {
                return(errorResult);
            }

            accountDetails.GeoIp   = IpAddressDetector.IpAddress;
            accountDetails.Id      = account.Id;
            accountDetails.Source  = model.Source;
            accountDetails.WebForm = FormIdBuilder.Build(model.FormId);

            await _auth.AccountOptinSetAsync(account, model.Optin);

            await _auth.AccountDetailsSetAsync(accountDetails);

            await _auth.AccountVisitorIdSetAsync(account, model.VisitorId);

            await NotificationManager.LegacyActivationCreatePassword(account);

            OauthLogger.CreateAccountWarn(Request, account, accountDetails, "registerLegal");

            return(Ok());
        }
 public async Task AccountDetailsSetAsync(ViewAccountDetails accountDetails)
 {
     await _context.AccountDetailsSetAsync(accountDetails);
 }