Esempio n. 1
0
        public ActionResult SignupCounsellor([FromBody] Counsellor counsellor)
        {
            _logger.LogInformation("Post: api/User/SignupCounsellor Invoke");
            ResponseModel           responseModel = new ResponseModel();
            ClientRequestToCreateId objclient     = new ClientRequestToCreateId();

            objclient.firstName  = counsellor.FirstName;
            objclient.lastName   = counsellor.LastName;
            objclient.email      = counsellor.Email;
            objclient.customerId = counsellor.ACECustomerId;
            // objclient.customerId = "a4534a91-f202-40e1-b91d-79738d647419";
            objclient.serviceTypeId        = _aceServiceTypeId;
            objclient.employerGroupId      = counsellor.GroupId;
            objclient.employerDepartmentId = counsellor.DeptId;
            objclient.employerDivisionId   = counsellor.DivisionId;
            objclient.postCode             = counsellor.Postcode;
            objclient.dateOfBirth          = counsellor.DateOfBirth;
            objclient.phoneNumber          = counsellor.MobileNo;
            //objclient.gender = counsellor.Gender;

            //objclient.firstName = "Thiruka";
            //objclient.lastName = "Naik";
            //objclient.email = "*****@*****.**";
            //objclient.customerId = "32e57fce-ad44-4da8-a366-26225033267a";
            //objclient.serviceTypeId = "48659344-d51b-4a63-9807-7b29846be375";
            //objclient.employerGroupId = "75b088b4-8bab-4b2c-b908-16deefb0576f";
            //objclient.employerDepartmentId = "82d3bb7b-6623-4552-b9c9-83951efad031";
            //objclient.employerDivisionId = "121960dc-cf53-44f6-b7ca-ccb7b5bffce9";
            //objclient.postCode = "1001";
            //objclient.dateOfBirth = "5-5-2016";
            //objclient.phoneNumber = "98567142365";
            ACEAPI objaceapi         = new ACEAPI();
            var    GetclientResponse = objaceapi.CreateClientId(objclient);

            if (GetclientResponse.id != null)
            {
                counsellor.ACEClientId = GetclientResponse.id;
                var result = _userService.SignupCounsellor(counsellor);
                if (result != null)
                {
                    EmailServiceHelper emailService = new EmailServiceHelper(_config, _email);
                    if (_isSendMailBySendGrid)
                    {
                        emailService.SignUpVerificationEmail(result).Wait();
                    }
                    responseModel.Message = "Success";
                    responseModel.Result  = result;
                }
            }



            else
            {
                responseModel.IsSuccess = false;
                responseModel.Message   = $"{counsellor.Email} Not Registered";
                responseModel.Result    = GetclientResponse.detail;
            }
            return(Ok(responseModel));
        }
        public async Task ForgotPassword_Cancel()
        {
            string cancelUrl  = null;
            string confirmUrl = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                EmailTemplates.UserAccountRecover,
                "alice@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = TestServerBuilderExtensions
                                .CreateServer(emailServiceMock);

            HttpClient client = server.CreateClient();

            // Call cancel url
            await client.RecoveryCancelGetValidAsync(cancelUrl);

            // Calling cancel url again shouldnt be possible
            await client.RecoveryCancelGetInvalidAsync(cancelUrl);

            // Calling confirm url shouldnt be possible after successfull
            // cancelation
            await client.RecoveryConfirmGetInvalidAsync(confirmUrl);
        }
Esempio n. 3
0
        public ActionResult Forgotpassword([FromBody] User user)
        {
            string message = "";

            _logger.LogInformation("POST: api/MobileUser/Forgotpassword Invoke");
            ResponseModel responseModel = new ResponseModel();
            var           result        = _userService.ForgotPassword(user, message);

            if (result.Item2.ToString() == "Success")
            {
                EmailServiceHelper emailService = new EmailServiceHelper(_config, _email);
                //Azure SendGrid Email Grid
                if (_isSendMailBySendGrid)
                {
                    emailService.ForgetPasswordMail(result.Item1).Wait();
                }
                //EmailServiceHelperForMobile.ForgetMessage(result.Item1);

                //Local Send Email
                if (!_isSendMailBySendGrid)
                {
                    emailService.localForgetMessage(result.Item1);
                }
                responseModel.IsSuccess = true;
                responseModel.Message   = "Success";
                responseModel.Result    = result.Item2.ToString();
            }
            else
            {
                responseModel.IsSuccess = false;
                responseModel.Result    = result.Item2.ToString();
            }
            return(Ok(responseModel));
        }
Esempio n. 4
0
        public ActionResult PostUser(User user)
        {
            _logger.LogInformation("POST: api/User/PostUser  Invoke");
            user.Password = RandomPassword.RandomGeneratePassword();
            user.Password = EncryptionDecryptionHelper.EncryptString(user.Password);
            ResponseModel responseModel = new ResponseModel();
            var           result        = _userService.PostUser(user, _hostingEnvironment.ContentRootPath.ToString(), folderLocation);

            if (result == null)
            {
                responseModel.IsSuccess = false;
                responseModel.Message   = "Record Not Created";
            }
            else
            {
                EmailServiceHelper emailService = new EmailServiceHelper(_config, _email);
                //Azure SendGrid Email Grid
                if (_isSendMailBySendGrid)
                {
                    emailService.AdminRegMessage(result).Wait();
                }

                ////local Send Email Grid
                //if (!_isSendMailBySendGrid)
                //    emailService.localUserRegMessage(result);

                responseModel.Result = result;
            }

            return(Ok(responseModel));
        }
        public async Task ChangeEmail_FoceUpdate()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                IdentityBaseConstants.EmailTemplates.UserAccountEmailChanged,
                "nerd@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = this.CreateServer(emailServiceMock);
            HttpClient client = await server.CreateAuthenticatedClient();

            string uri = $"/api/useraccounts/{aliceId}/change_email";
            HttpResponseMessage response = await client.PostJsonAsync(uri, new
            {
                Email    = "nerd@localhost",
                ClientId = "mvc.hybrid",
                Force    = true
            });

            response.EnsureSuccessStatusCode();
            var json = response.Content.ReadAsStringAsync().Result;
        }
Esempio n. 6
0
        private async Task <HttpResponseMessage> GetAndPostRecoverForm(
            bool loginAfterAccountRecovery,
            Action <TestServer, HttpClient> gotServer,
            Action <string, string> gotMail)
        {
            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                IdentityBaseConstants.EmailTemplates.UserAccountRecover,
                "alice@localhost",
                (templateName, emailTo, viewData, isHtml) =>
            {
                // 3. Get confirm url
                var confirmUrl = viewData.ToDictionary()["ConfirmUrl"] as string;
                var cancelUrl  = viewData.ToDictionary()["CancelUrl"] as string;

                gotMail(confirmUrl, cancelUrl);
            });

            // Create a server with custom configuration
            var config = ConfigBuilder.Default
                         // remove the default service since we mocking it
                         .RemoveDefaultMailService()
                         // dont login after recovery
                         .Alter("App:LoginAfterAccountRecovery", loginAfterAccountRecovery ? "true" : "false")
                         .Build();

            var server = TestServerBuilder.BuildServer <Startup>(config, (services) =>
            {
                services.AddSingleton(emailServiceMock.Object);
            });
            var client = server.CreateClient();

            gotServer(server, client);

            // Call the recovery page
            var response = await client.GetAsync(
                $"/recover?returnUrl={Constants.ReturnUrl}");

            response.EnsureSuccessStatusCode();

            // Fill out the form and submit
            var doc = await response.Content.ReadAsHtmlDocumentAsync();

            var form = new Dictionary <string, string>
            {
                { "Email", "alice@localhost" },
                { "__RequestVerificationToken", doc.GetAntiForgeryToken() }
            };

            var response2 = await client.PostFormAsync(doc.GetFormAction(), form, response);

            response2.EnsureSuccessStatusCode();

            return(response2);
        }
        public async Task ForgotPassword_Confirm_AddNewPassword_Login()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                EmailTemplates.UserAccountRecover,
                "alice@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = TestServerBuilderExtensions
                                .CreateServer(emailServiceMock);

            HttpClient client = server.CreateClient();

            // 1. Call the recovery page and Fill out the form and submit
            HttpResponseMessage response = await client
                                           .RecoveryGetAndPostFormAsync("alice@localhost");

            Assert.NotNull(confirmUrl);
            Assert.NotNull(cancelUrl);

            // Call the confirmation link and fill out the form
            HttpResponseMessage confirmResponse = await client
                                                  .RecoveryConfirmGetAndPostFormAsync(
                confirmUrl,
                "new-password"
                );

            HttpResponseMessage consentPostResponse = await
                                                      client.ConstentPostFormAsync(false, confirmResponse);

            // Calling confirm url again shouldnt be possible
            await client.RecoveryConfirmGetInvalidAsync(cancelUrl);

            // Calling cancel url shouldnt be possible after successfull
            // confirmation
            await client.RecoveryCancelGetInvalidAsync(cancelUrl);

            HttpResponseMessage loginResponse = await client
                                                .LoginGetAndPostFormAsync("alice@localhost", "new-password");

            loginResponse.ShouldBeRedirectedToAuthorizeEndpoint();
        }
Esempio n. 8
0
            public async Task Invite_User()
            {
                string confirmUrl = null;
                string cancelUrl  = null;


                // Mock the email service to intercept the outgoing email messages
                var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                    IdentityBaseConstants.EmailTemplates.UserAccountInvited,
                    "invited@localhost",
                    (templateName, emailTo, viewData, isHtml) =>
                {
                    // 3. Get confirm url
                    confirmUrl = viewData.ToDictionary()["ConfirmUrl"] as string;
                    cancelUrl  = viewData.ToDictionary()["CancelUrl"] as string;
                });

                // Create a server with custom configuration
                var config = ConfigBuilder.Default
                             // remove the default service since we mocking it
                             .RemoveDefaultMailService()
                             .Alter("App:EnableInvitationCreateEndpoint", "true")
                             .Build();

                var server = TestServerBuilder.BuildServer <Startup>(config, (services) =>
                {
                    services.AddSingleton(emailServiceMock.Object);
                });
                var client = server.CreateClient();

                // Act
                var response = await client.PutJsonAsync("/invitations", new
                {
                    Email    = "invited@localhost",
                    ClientId = "mvc.hybrid"
                });

                response.EnsureSuccessStatusCode();

                // Try to follow the confirmation link again it should return an error
                var response3 = await client.GetAsync(confirmUrl);

                response3.StatusCode.Should().Be(HttpStatusCode.OK);
                var doc2 = await response3.Content.ReadAsHtmlDocumentAsync();
            }
Esempio n. 9
0
        public async Task Invite_Confirm_AddPassword_Login()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                IdentityBaseConstants.EmailTemplates.UserAccountInvited,
                "invited@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = this.CreateServer(emailServiceMock);
            HttpClient client = await server.CreateAuthenticatedClient();

            HttpResponseMessage response = await client
                                           .PutJsonAsync("/api/invitations", new
            {
                Email    = "invited@localhost",
                ClientId = "mvc.hybrid"
            });

            response.EnsureSuccessStatusCode();
            response.AssertSchema(Schemas.InvitationsPostResponse);

            Assert.NotNull(confirmUrl);
            Assert.NotNull(cancelUrl);

            // Call the confirmation link and fill out the form
            HttpResponseMessage confirmResponse = await client
                                                  .RegisterConfirmGetAndPostFormAsync(
                confirmUrl,
                "supersecret"
                );

            // confirmResponse.ShouldBeRedirectedToAuthorizeEndpoint();
        }
Esempio n. 10
0
        public async Task ChangeEmail_Confirm_Login()
        {
            string confirmUrl = null;
            string cancelUrl  = null;

            // Mock the email service to intercept the outgoing email messages
            var emailServiceMock = EmailServiceHelper.GetEmailServiceMock(
                IdentityBaseConstants.EmailTemplates.UserAccountEmailChanged,
                "nerd@localhost", (templateName, emailTo, viewData, isHtml) =>
            {
                // 2. Get confirm url and call it
                confirmUrl = viewData
                             .ToDictionary()["ConfirmUrl"].ToString();

                cancelUrl = viewData
                            .ToDictionary()["CancelUrl"].ToString();
            });

            TestServer server = this.CreateServer(emailServiceMock);
            HttpClient client = await server.CreateAuthenticatedClient();

            string uri = $"/api/useraccounts/{aliceId}/change_email";
            HttpResponseMessage response = await client.PostJsonAsync(uri, new
            {
                Email    = "nerd@localhost",
                ClientId = "mvc.hybrid",
                Force    = false
            });

            response.EnsureSuccessStatusCode();
            // response.AssertSchema(Schemas.InvitationsPostResponse);

            Assert.NotNull(confirmUrl);
            Assert.NotNull(cancelUrl);

            // Post password

            // Try authenticate
        }