Ejemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new PinterestUser {
                    UserName = model.Email, Email = model.Email
                };
                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>");

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

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public string SaveAccountDeatils(OAuthTokens tokens, string userId, string Email)
        {
            try
            {
                AccessDetails accessToken = new AccessDetails()
                {
                    AccessToken = tokens.access_token
                };
                var           returnMessage       = string.Empty;
                PinterestUser profile             = GetUserprofile(accessToken);
                var           checkAccountIsAvail = _socialMedia.Get().Include(x => x.AccessDetails).Where(x => x.SMId == profile.data.id.ToString() && x.IsDeleted == false).FirstOrDefault();
                if (checkAccountIsAvail == null)
                {
                    SocialMedia socialDetails = new SocialMedia()
                    {
                        UserId        = userId,
                        Provider      = SocialMediaProviders.Pinterest.ToString(),
                        AccessDetails = new AccessDetails {
                            AccessToken = tokens.access_token
                        },

                        SMId        = profile.data.id,
                        Status      = true,
                        UserName    = profile.data.username,
                        AccSettings = new AccSettings()
                    };
                    socialDetails.AccSettings.UserManagement.Add(new UserManagement {
                        Email = Email, userId = userId, Role = "Owner"
                    });
                    _socialMedia.Add(socialDetails);
                }
                else if (checkAccountIsAvail.UserId == userId)
                {
                    checkAccountIsAvail.AccessDetails.AccessToken = tokens.access_token;
                    checkAccountIsAvail.IsInvalid = false;
                    checkAccountIsAvail.Status    = true;
                    returnMessage = "Already added.";
                }
                else
                {
                    checkAccountIsAvail.AccessDetails.AccessToken = tokens.access_token;
                    checkAccountIsAvail.IsInvalid = false;
                    checkAccountIsAvail.Status    = true;
                    returnMessage = "Cannot add this account, as already added by other user.";
                }
                _unitOfWork.Commit();
                return(returnMessage);
            }
            catch (Exception)
            {
                return("Something went wrong.");
            }
        }
Ejemplo n.º 3
0
        protected override void Seed(Week7_Lab.Models.PinterestDbContext context)
        {
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var userManager = new UserManager <PinterestUser>(new UserStore <PinterestUser>(context));

            if (userManager.FindByName("ahudson") == null)
            {
                var aaron = new PinterestUser()
                {
                    FirstName = "Aaron", LastName = "Hudson", Email = "*****@*****.**", UserName = "******"
                };
                userManager.Create(aaron, "Password123!");
            }

            context.SaveChanges();

            var img1 = GetImageByteArray("http://scrapetv.com/News/News%20Pages/Entertainment/images-3/star-wars-poster.jpg");
            var img2 = GetImageByteArray("http://fc06.deviantart.net/fs51/f/2009/258/2/f/2fca1bc9ddcc147ef674d2eebb14ee3a.jpg");
            var img3 = GetImageByteArray("http://www.bollygraph.com/wp-content/uploads/2013/01/Godfather-1972.jpg");
            var img4 = GetImageByteArray("http://img4.wikia.nocookie.net/__cb20090618213543/indianajones/images/0/04/Raidersteaser.jpg");
            var img5 = GetImageByteArray("https://pabblogger.files.wordpress.com/2011/03/dark_knight.jpg");
            var img6 = GetImageByteArray("http://4.bp.blogspot.com/-sY6VnEIBCNU/UNSMSN7zo9I/AAAAAAAAAZ8/0OORh5M-V70/s1600/The+Terminator+Poster.jpg");
            var img7 = GetImageByteArray("https://fanart.tv/fanart/movies/278/movieposter/the-shawshank-redemption-5223c8231afe1.jpg");
            var user = context.Users.FirstOrDefault(x => x.UserName == "*****@*****.**");

            context.Pins.AddOrUpdate(p => p.ImageLink,
                                     new Models.Pin {
                Image = img1, ImageLink = "http://www.imdb.com/title/tt0076759", Note = "They teach a slave boy to become a Jedi, who later becomes mutilated and becomes dedicated to evil. They find a new boy who is pure of heart and teach him to fight Darth Vader.", WhoPinned = user
            },
                                     new Models.Pin {
                Image = img2, ImageLink = "http://www.imdb.com/title/tt0133093", Note = "A black man comes to a white guy named Neo and asks him to choose between colours, which unbeknownst to him represented life choices. When he chooses the pill that 'goes down the rabbit hole', he gets thrust into a digital world in which robots have taken over the world secretly and they have super powers.", WhoPinned = user
            },
                                     new Models.Pin {
                Image = img3, ImageLink = "http://www.imdb.com/title/tt0068646/", Note = "It’s about a mob family, and I’m not sure about the rest. There is a quote at the end where the godfather says something, but I don’t remember what it is.", WhoPinned = user
            },
                                     new Models.Pin {
                Image = img4, ImageLink = "http://www.imdb.com/title/tt0082971/", Note = "A guy who runs into tombs and pyramids and tries to collect artifacts, but always runs into boobie traps. Also, there are cursed people and things that he has to deal with as well.", WhoPinned = user
            },
                                     new Models.Pin {
                Image = img5, ImageLink = "http://www.imdb.com/title/tt0468569", Note = "A group of people control the financial and political systems of as much as they can get their hands on. Batmans parents donate to the poor and create programs to prevent that from happening. Thus, they try another method to destroy it by releasing a toxin that makes people go criminally insane. However, batman manages to foil their plans.", WhoPinned = user
            },
                                     new Models.Pin {
                Image = img6, ImageLink = "http://www.imdb.com/title/tt0088247", Note = "A movie about a robot who travels back in time to save, what I think I remember being as his inventor, from evil robots who try to change the future by killing him.", WhoPinned = user
            },
                                     new Models.Pin {
                Image = img7, ImageLink = "http://www.imdb.com/title/tt0111161", Note = "A scary movie about people who run into some crazy person that wants to kill them.", WhoPinned = user
            }
                                     );
        }
        public PinterestUser GetUserprofile(AccessDetails Token)
        {
            try
            {
                var request = new RestRequest("v1/me", Method.GET);
                //request.AddHeader("Content-Type", "application/json");
                //request.AddHeader("Authorization", "OAuth " + token);
                request.AddParameter("access_token", Token.AccessToken);
                request.AddParameter("fields", "first_name,id,last_name,url,username");

                var response = WebServiceHelper.WebRequest(request, ApiURL);
                JsonDeserializer deserial = new JsonDeserializer();
                PinterestUser    result   = deserial.Deserialize <PinterestUser>(response);
                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        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 PinterestUser {
                    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> 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 PinterestUser { 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 PinterestUser { UserName = model.Email, Email = model.Email };
                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>");

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

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of <see cref="PinterestGetUserResponseBody"/> parsed from the specified <paramref name="obj"/>.
 /// </summary>
 /// <param name="obj">The <see cref="JObject"/> to be parsed.</param>
 protected PinterestGetUserResponseBody(JObject obj) : base(obj)
 {
     Data = obj.GetObject("data", PinterestUser.Parse);
 }