Esempio n. 1
0
 public SimpleUser Create(ApplicationUser appUser)
 {
     return(new SimpleUser
     {
         Id = appUser.Id,
         Username = appUser.UserName,
         Email = appUser.Email,
         EmailConfirmed = appUser.EmailConfirmed,
         JoinDate = appUser.JoinDate
     });
 }
Esempio n. 2
0
        public async Task <IHttpActionResult> Post(AccountModelBinding createUserModel)
        {
            var user = new ApplicationUser()
            {
                UserName = createUserModel.Username,
                Email    = createUserModel.Email,
                JoinDate = DateTime.Now.Date,
            };

            IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password);

            if (!addUserResult.Succeeded)
            {
                return(GetErrorResult(addUserResult));
            }

            var code = await AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id);

            string site;

#if DEBUG
            site = Constants.Site;
#else
            site = String.Format("https://{0}.azurewebsites.net/",
                                 Environment.ExpandEnvironmentVariables("%WEBSITE_SITE_NAME%")
                                 .ToLower());
#endif
            var callbackUrl      = site + $"account/confirmemail?userId={Uri.EscapeDataString(user.Id)}&code={Uri.EscapeDataString(code)}";
            var subject          = "Welcome to Smalldebts!";
            var plainTextContent = "Please confirm your account by clicking this link:" + callbackUrl;
            var htmlContent      = "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>";


            var emailSent = _mailProvider.SendEmailAsync(
                new Email()
            {
                Address = "*****@*****.**", Name = "Smalldebts team"
            },
                "Welcome to Smalldebts!",
                plainTextContent,
                htmlContent,
                new Email()
            {
                Address = user.Email, Name = user.UserName
            });

            return(Created(callbackUrl, TheModelFactory.Create(user)));
        }