private void AuthorPublNext_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(authorName.Text))
            {
                MessageBox.Show("Необходимо ввести ФИО Автора");
                authorName.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(JobAddress.Text))
            {
                MessageBox.Show("Необходимо ввести место работы");
                JobAddress.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(AuthEmail.Text))
            {
                MessageBox.Show("Необходимо ввести электронную почту");
                AuthEmail.Focus();
                return;
            }
            _author = new Authors(authorName.Text, JobAddress.Text, AuthEmail.Text);
            Pages.NewPublAboutPubl.NewAuthorAdded(_author);

            NavigationService.Navigate(Pages.NewPublAboutPublisher);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> updateAddress(UpdateAddressViewModel item)
        {
            //Get the current user
            var user = await GetCurrentUserAsync();

            //Get current user address
            //Create a country object from the form the user has submitted. Region id will be set to 1 for now.
            Countries country = new Countries {
                countryName = item.countryName, RegionsId = 1
            };
            //Check if the country exists
            var countryExist = _addressProvider.checkIfCountryExists(country);

            //If there is no country add it to the db
            if (!countryExist)
            {
                //Add the country to the db
                _addressProvider.addCountry(country);
            }
            //Create a location object
            Locations location = new Locations
            {
                CountriesId  = _addressProvider.getCountryId(country),
                postcode     = item.location.postcode,
                state        = item.location.state,
                streetName   = item.location.streetName,
                streetNumber = item.location.streetNumber,
                suburb       = item.location.suburb,
                unitNumber   = item.location.unitNumber
            };
            //Check if location exists
            var locationExist = _addressProvider.checkIfLocationExists(location);

            //If location does not exist create it in the db
            if (!locationExist)
            {
                _addressProvider.addLocation(location);
            }
            int newLocId = _addressProvider.getLocationId(location);
            int userAddressIDtoUpdate = item.userAddressID;
            var oldAddress            = _addressProvider.getLocationByUserAddressID(userAddressIDtoUpdate);
            //Get list of all oranisations which are part of this address.
            var org = _organisationProvider.getAllAddressOrganisationLinks(userAddressIDtoUpdate);
            List <UserOrganisationLinks> listofOrgs = new List <UserOrganisationLinks>();

            foreach (var link in org)
            {
                listofOrgs.Add((_organisationProvider.getUserOrganisationLink(link.UserOrganisationLinksId)));
            }
            //Now we need to update the users address with the new location ID.
            _addressProvider.updateUserAddress(userAddressIDtoUpdate, newLocId, item.userAddress.AddressType);
            AuthEmail _authEmail = new AuthEmail();

            _authEmail.SendEmailToUpdateAddress(oldAddress.ToString(), location.ToString(), listofOrgs, user);
            return(RedirectToAction("ManageAddresses"));
        }
Exemplo n.º 3
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IEmailSender emailSender,
     ISmsSender smsSender,
     ILoggerFactory loggerFactory
     )
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailSender   = emailSender;
     _smsSender     = smsSender;
     _logger        = loggerFactory.CreateLogger <AccountController>();
     _authEmail     = new AuthEmail();
     _emailProvider = new EmailProvider();
 }
Exemplo n.º 4
0
 public IdentityController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IEmailSender emailSender,
     ISmsSender smsSender,
     ILoggerFactory loggerFactory)
 {
     _userManager          = userManager;
     _signInManager        = signInManager;
     _emailSender          = emailSender;
     _smsSender            = smsSender;
     _logger               = loggerFactory.CreateLogger <IdentityController>();
     _dbContext            = new ApplicationDbContext();
     _addressProvider      = new AddressProvider();
     _emailProvider        = new EmailProvider();
     _authEmail            = new AuthEmail();
     _organisationProvider = new OrganisationProvider();
 }
Exemplo n.º 5
0
        public async Task TestMethod1()
        {
            using var authMessagesStream = typeof(IAuthProcess).Assembly.GetManifestResourceStream("LazyStackAuth.AuthMessages.json");
            using var awsSettingsStream  = typeof(PetStoreIntegrationTest).Assembly.GetManifestResourceStream("PetStoreTests.AwsSettings.json");
            using var methodMapStream    = typeof(PetStore).Assembly.GetManifestResourceStream("PetStoreClientSDK.MethodMap.json");
            IConfiguration appConfig = new ConfigurationBuilder()
                                       .AddUserSecrets <PetStoreIntegrationTest>() //  used to get gmail account credentials for auth code
                                       .AddJsonStream(awsSettingsStream)
                                       .AddJsonStream(authMessagesStream)
                                       .AddJsonStream(methodMapStream)
                                       .Build();

            IServiceCollection services = new ServiceCollection();
            IServiceProvider   serviceProvider;

            services.AddSingleton <IConfiguration>(appConfig);
            // LoginFormat(IConfiguration)
            services.AddSingleton <ILoginFormat, LoginFormat>();

            // PasswordFormat(IConfiguration)
            services.AddSingleton <IPasswordFormat, PasswordFormat>();

            // EmailFormat(IConfiguration)
            services.AddSingleton <IEmailFormat, EmailFormat>();

            // PhoneFormat(IConfiguration)
            services.AddSingleton <IPhoneFormat, PhoneFormat>();

            // CodeFormat(IConfiguration)
            services.AddSingleton <ICodeFormat, CodeFormat>();

            // AuthProviderCognito(IConfiguration, ILoginFormat, IPasswordFormat, IEmailFormat, ICodeFormat, IPhoneFormat)
            services.AddSingleton <IAuthProvider, AuthProviderCognito>();

            // AuthProcess(IConfiguration, IAuthProvider)
            services.AddSingleton <IAuthProcess, AuthProcess>(); // depends on IConfiguration, IAuthProvider

            serviceProvider = services.BuildServiceProvider();

            var authProvider = serviceProvider.GetService <IAuthProvider>() as AuthProviderCognito;
            var authProcess  = serviceProvider.GetService <IAuthProcess>();

            // Signup
            var now      = DateTime.Now;
            var login    = $"TestUser{now.Year}-{now.Month}-{now.Day}-{now.Hour}-{now.Minute}-{now.Second}";
            var password = "******";

            // Use Google email alias feature to allow us to use a single gmail account for our testing
            // ex: [email protected] becomes [email protected]
            // This avoids AWS complaining that the email already exists
            // These are one-time use aliases and Cognito accounts
            var email      = appConfig["Gmail:Email"];
            var emailParts = email.Split("@");

            email = emailParts[0] + "+" + login + "@" + emailParts[1];

            // Start Sign Up process
            Assert.IsTrue(await authProcess.StartSignUpAsync() == AuthEventEnum.AuthChallenge);
            Assert.IsTrue(authProcess.CurrentAuthProcess == AuthProcessEnum.SigningUp);

            // Simulate collection of Login from user
            Assert.IsTrue(authProcess.CurrentChallenge == AuthChallengeEnum.Login);
            authProcess.Login = login;
            Assert.IsTrue(await authProcess.VerifyLoginAsync() == AuthEventEnum.AuthChallenge);

            // Simulate collection of Password from user
            Assert.IsTrue(authProcess.CurrentChallenge == AuthChallengeEnum.Password);
            authProcess.Password = password;
            Assert.IsTrue(await authProcess.VerifyPasswordAsync() == AuthEventEnum.AuthChallenge);

            // Simulate collection of Email from user
            Assert.IsTrue(authProcess.CurrentChallenge == AuthChallengeEnum.Email);
            authProcess.Email = email;
            var verificationCodeSendTime = DateTime.UtcNow; // verificationCode sent after this time

            Thread.Sleep(5000);                             // Account for a little drive among local and remote clock
            Assert.IsTrue(await authProcess.VerifyEmailAsync() == AuthEventEnum.AuthChallenge);

            // Simulate collection of Code from user - AWS Sends the code to the email account
            Assert.IsTrue(authProcess.CurrentChallenge == AuthChallengeEnum.Code);
            var verificationCode = AuthEmail.GetAuthCode(appConfig, email);

            Assert.IsNotNull(verificationCode);
            authProcess.Code = verificationCode;
            // Verifying the code finalizes the sign up process
            Assert.IsTrue(await authProcess.VerifyCodeAsync() == AuthEventEnum.SignedUp);
            Assert.IsTrue(authProcess.CurrentAuthProcess == AuthProcessEnum.None);
            Assert.IsTrue(authProcess.CurrentChallenge == AuthChallengeEnum.None);
            Assert.IsTrue(authProcess.IsSignedIn == false);

            // Start SignIn process
            Assert.IsTrue(await authProcess.StartSignInAsync() == AuthEventEnum.AuthChallenge);
            Assert.IsTrue(authProcess.CurrentAuthProcess == AuthProcessEnum.SigningIn);

            // Simulate collection of Password from user
            Assert.IsTrue(authProcess.CurrentChallenge == AuthChallengeEnum.Login);
            authProcess.Password = password;
            Assert.IsTrue(await authProcess.VerifyLoginAsync() == AuthEventEnum.AuthChallenge);

            // Simulate collection of Password from user
            Assert.IsTrue(authProcess.CurrentChallenge == AuthChallengeEnum.Password);
            authProcess.Password = password;
            // Verifying password finalizes SigningIn process
            Assert.IsTrue(await authProcess.VerifyPasswordAsync() == AuthEventEnum.SignedIn);
            Assert.IsTrue(authProcess.CurrentAuthProcess == AuthProcessEnum.None);
            Assert.IsTrue(authProcess.CurrentChallenge == AuthChallengeEnum.None);
            Assert.IsTrue(authProcess.IsSignedIn == true);

            //////////////////////////////////////////////////////////////
            // Use PetStore library to call the ApiGateways in our stack
            //////////////////////////////////////////////////////////////

            // Creating the LzHttpClient which knows how to make secure calls against AWS ApiGateways
            var lzHttpClient = new LzHttpClient(appConfig, authProvider, null);

            // Create the PetStore lib instance that makes calling the stack easy
            var petStore = new PetStore(lzHttpClient);

            // Call PetStore.SeedPetsAsync -- it's ok if the pet records already exist
            await petStore.SeedPetsAsync();

            // Retrieve pet record by Id
            var pet = await petStore.GetPetByIdAsync(1);
        }