示例#1
0
        public async Task<IActionResult> AddPersonAsync(Person person)
        {
            Console.WriteLine($"person {person.Name}" );

            if (!CheckEmailAddress(person.Email))
            {
                return Ok("Email in incorrect format");
            }

            // Make sure Email Address Does not below to anyone else
            var inUse = await _personRepository.GetPersonByEmailAsync(person.Email);
            if (inUse != null)
            {
                return Ok("Email Address already in Use, select distinct email address");
            }

            person.ChangePassword = "******";

            var success = await _personRepository.AddPersonAsync(person);

            if (success)
            {
                person.Token = _tokenClass.CreateToken();
                person.TokenDate = DateTime.UtcNow.ToString();
                await UpdatePersonAsync(person);

                var callBackUrl = String.Empty;
            
                try
                {
                    callBackUrl = Url.Action("ConfirmEmail", "Email");
                    Console.WriteLine($"We got here with a url value of {callBackUrl}");
                } 
                catch (Exception ex)
                { 
                    Console.WriteLine($"Exception occured when generating link for email {ex}");
                }

                var confirmationLink = _emailHelper.ConfirmationLinkBody(person, callBackUrl);
                bool emailResponse = await _emailHelper.SendEmail(person.Name, person.Email, confirmationLink, 
                    _emailHelper.ConfirmationLinkSubject());

             
                if (emailResponse)
                {
                    Console.WriteLine($"Valid Email Address {person.Email}");
                }
                else
                {
                    Console.WriteLine($"Invalid Email Address {person.Email}");
                    return Ok($"Invalid Email Address {person.Email}");
                }
            }

            Console.WriteLine($"success {success}" );
            return Ok(success);
        }
示例#2
0
        public async Task <IActionResult> ResendEmail(string username, string password)
        {
            var person = await _personRepository.GetPersonAsync(username);

            if (person == null || string.IsNullOrEmpty(person.HashedPassword))
            {
                return(Ok());
            }

            person.Token     = _tokenClass.CreateToken();
            person.TokenDate = DateTime.UtcNow.ToShortDateString();
            await _personRepository.UpdatePersonAsync(person);

            var callBackUrl = String.Empty;

            try
            {
                callBackUrl = Url.Action("ConfirmEmail", "Email");
                Console.WriteLine($"We got here with a url value of {callBackUrl}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception occured when generating link for email {ex}");
            }

            var  confirmationLink = _emailHelper.ConfirmationLinkBody(person, callBackUrl);
            bool emailResponse    = await _emailHelper.SendEmail(person.Name, person.Email,
                                                                 confirmationLink, _emailHelper.ConfirmationLinkSubject());

            if (emailResponse)
            {
                Console.WriteLine($"Valid Email Address {person.Email}");
            }
            else
            {
                Console.WriteLine($"Invalid Email Address {person.Email}");
                return(Ok($"Invalid Email Address {person.Email}"));
            }

            Console.WriteLine($"success");
            return(Ok("success"));
        }