コード例 #1
0
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var info = await Authentication.GetExternalLoginInfoAsync();
            if (info == null)
            {
                return InternalServerError();
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user);
            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (!result.Succeeded)
            {
                return GetErrorResult(result); 
            }
            return Ok();
        }
コード例 #2
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }
            else
            {
                // Generate the Email Confirmation Token
                string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                // UrlEncode the token
                code = HttpUtility.UrlEncode(code);

                // Get the Host from the appSettings.  http://www.myclientsite.com
                string clientSite = AppSettingsConfig.ClientSite;

                // Build the Url that will be used for the link in the email message.
                var callbackUrl = clientSite + "/#/confirmemail?userId=" + user.Id + "&code=" + code;

                // Build the callback message for the email.
                var callbackMessage = "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>";

                // Send the email. Remember to set the system.net/mailSettings/smtp/network configuration in the web.config.
                await UserManager.SendEmailAsync(user.Id, "Confirm your account", callbackMessage);
            }

            return Ok();
        }