Beispiel #1
0
 public async Task<ApplicationUser> UpdateHeroImageAsync(ApplicationUser user)
 {
     var current = _dbContext.Users.Single(u => u.Email == _owin.Authentication.User.Identity.Name);
     current.HeroUri = user.HeroUri;
     await _dbContext.SaveChangesAsync();
     return current;
 }
Beispiel #2
0
 public async Task<ApplicationUser> UpdateHeroAttributesAsync(ApplicationUser user)
 {
     var current = _dbContext.Users.Single(u => u.Email == _owin.Authentication.User.Identity.Name);
     current.Title = user.Title;
     current.Mission = user.Mission;
     current.ContactUs = user.ContactUs;
     current.PageUri = user.PageUri;
     await _dbContext.SaveChangesAsync();
     return current;
 }
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email, AtHandle = model.AtHandle };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your SavingChance.com account");

                    // Uncomment to debug locally 
                    // TempData["ViewBagLink"] = callbackUrl;

                    ViewBag.Message = "We have sent you a confirmation email to the address you specified.  Please confirm your account by following the link in the email.  The email should arrive momentarily.";

                    return View("Info");
                    //return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public async Task<HttpResponseMessage> Update(UpdateHeroBindingModel model)
 {
     try
     {
         var user = new ApplicationUser()
         {
             Title = model.Title,
             Mission = model.Mission,
             ContactUs = model.ContactUs,
             PageUri = ToUri(model.PageUri)
         };
         return Request.CreateResponse<ApplicationUser>(await _userService.UpdateHeroAttributesAsync(user));
     }
     catch(Exception ex)
     {
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString());
     }
 }
        public async Task<HttpResponseMessage> SetImage()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            
            string root = HttpContext.Current.Server.MapPath("~/Users/Media/Images");

            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            
            var provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                var file = provider.FileData.First();
                var newName = file.Headers.ContentDisposition.FileName.Replace("\"", "");
                var newPath = Path.Combine(Path.GetDirectoryName(file.LocalFileName), newName);
                if (File.Exists(newPath)) File.Delete(newPath);
                File.Move(file.LocalFileName,  newPath);

                var user = new ApplicationUser()
                {
                    HeroUri = VirtualPathUtility.ToAbsolute(MapVirtual(newPath))
                };

                return Request.CreateResponse<ApplicationUser>(await _userService.UpdateHeroImageAsync(user));
            }
            catch (System.Exception e)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.ToString());
            }
        }
        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();
        }
        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);
            }

            return Ok();
        }