示例#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);
            }
            user.Equals(User.Identity.IsAuthenticated);
            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)
            {
                //Email
                var message = new SendGridMessage();
                message.From = new MailAddress("*****@*****.**");

                message.AddTo(user.Email);
                message.Subject = "Thanks for registering with my Health App!";
                message.Text = "Thanks for registering with my Health App!";

                var credentials = new NetworkCredential("0", "0");
                var transportWeb = new Web("0");

                await transportWeb.DeliverAsync(message);
            }
            else
            {
                return GetErrorResult(result);
            }
            return Ok();
        }