Example #1
0
        private void FullCreateFormSaveUser(CreateAccountModel model)
        {
            var user = SaveUser(model);

            SendWelcomeEmail(user);
            SendVerificationEmail(user);

            this.StoreSuccess("Your account was created successfully");
            CookieHelpers.WriteCookie("lc", "uid", user.ID.ToString(), DateTime.Now.AddDays(30));
        }
Example #2
0
 private User SaveUser(CreateAccountModel model)
 {
     //Save the User
     var user = Mapper.Map<CreateAccountModel, User>(model);
     user.IsActive = true;
     user.DateOfBirth = DateTime.Parse(model.DateOfBirth);
     _us.Save(user);
     return user;
 }
Example #3
0
        private static void ConnectAuthAccountToUser(CreateAccountModel model, User user)
        {
            //Store the auth tokens for whatever service
            var userAuth = new UserAuthenticationProfile
            {
                UserID = user.ID,
                Platform = "Web",
                ServiceUsername = model.AuthScreenname,
                Token = model.AuthToken,
                TokenSecret = model.AuthTokenSecret
            };

            switch (model.AuthService)
            {
                case "twitter":
                    {
                        userAuth.Service = AuthenticationServices.TWITTER.ToString();
                        break;
                    }
                case "facebook":
                    {
                        userAuth.Service = AuthenticationServices.FACEBOOK.ToString();
                        break;
                    }
            }

            new UserAuthenticationProfileService().Save(userAuth);
        }
Example #4
0
        public virtual ActionResult Twitter()
        {
            try
            {
            
                var twitterAuth = Request.QueryString["oauth_token"];
                if (String.IsNullOrEmpty(twitterAuth))
                {
                    this.StoreError("There was a problem connecting to your Twitter account");
                    return RedirectToAction("Signup", new { InPopUp });
                }

                var accessTokenResponse = OAuthUtility.GetAccessTokenDuringCallback(TwitterHelper.TwitterConsumerKey, TwitterHelper.TwitterConsumerSecret);

                var twitterUser = TwitterHelper.GetUser(accessTokenResponse.Token,
                                                        accessTokenResponse.TokenSecret,
                                                        accessTokenResponse.ScreenName);

                if (twitterUser == null)
                {
                    this.StoreError("There was a problem connecting to your Twitter account");
                    return RedirectToAction("Signup", new { InPopUp });
                }

                //Check if this user already exists. If so login and redirect to the homepage
                var userId = CheckConnectedAccountUserExists(accessTokenResponse.ScreenName, AuthenticationServices.TWITTER, accessTokenResponse.Token, accessTokenResponse.TokenSecret);
                if (userId != Guid.Empty)
                {
                    CookieHelpers.WriteCookie("lc", "uid", userId.ToString());
                    RecordTheLogin(userId);

                    if (InPopUp)
                        return RedirectToAction("CloseAndRefresh", "Account");
                    
                    return RedirectToAction("Index", "Home");
                }



                //Get the larger profile pic from twitter
                var req = (HttpWebRequest)WebRequest.Create(string.Format("https://api.twitter.com/1/users/profile_image?screen_name={0}&size=original", twitterUser.ResponseObject.ScreenName));
                req.Method = "HEAD";
                var myResp = (HttpWebResponse)req.GetResponse();
                var profileImage = myResp.StatusCode == HttpStatusCode.OK ? myResp.ResponseUri.AbsoluteUri : twitterUser.ResponseObject.ProfileImageLocation;

                var splitName = twitterUser.ResponseObject.Name.Split(new[] { " " }, StringSplitOptions.None);

                var model = new CreateAccountModel()
                {
                    AuthToken = accessTokenResponse.Token,
                    AuthTokenSecret = accessTokenResponse.TokenSecret,
                    AuthScreenname = accessTokenResponse.ScreenName,
                    FirstName = splitName[0],
                    LastName = splitName[1],
                    DisplayProfileImage = profileImage,
                    ProfileImage = twitterUser.ResponseObject.ProfileImageLocation,
                    ServiceUserName = twitterUser.ResponseObject.ScreenName,
                    AuthService = "twitter",
                    InPopUp = InPopUp
                };

                //Continue to Step 2
                return View(model);
            }
            catch (Exception)
            {
                this.StoreError("There was a problem connecting to your twitter account");
                return RedirectToAction("Signup", new { InPopUp });
            }
        }
Example #5
0
        private bool AreAccountDetailsValid(CreateAccountModel model)
        {
            //Check to see if this account already exists
            var userTest = _us.GetUserByUsername(model.Username);
            if (userTest != null)
            {
                ModelState.AddModelError(string.Empty, string.Format("The username {0} is already in use, please try another username", userTest.Username));
                model.Username = "";
                return false;
            }

            //Check to see if this email address already exists
            var emailTest = _us.GetUserByEmail(model.EmailAddress);
            if (emailTest != null)
            {
                ModelState.AddModelError(string.Empty, string.Format("The email address {0} is already in use, please a different email address", emailTest.EmailAddress));
                model.EmailAddress = "";
                return false;
            }

            //Ensure the User is over 13
            if (model.DateOfBirth != null && (DateTime.Now - DateTime.Parse(model.DateOfBirth)).Days / 366 < 13)
            {
                ModelState.AddModelError(string.Empty, "You must be must be 13 years of age or older to use Epilogger.");
                return false;
            }

            return true;
        }
Example #6
0
        public virtual ActionResult Email(CreateAccountModel model)
        {
            if (ModelState.IsValid)
            {
                if (!AreAccountDetailsValid(model))
                {
                    return View(model);
                }

                var user = new User();
                try
                {
                    FullCreateFormSaveUser(model);

                    if (model.InPopUp)
                        return RedirectToAction("ConnectTwitter", "Account");

                    return RedirectToAction("Index", "Home");
                }
                catch (Exception ex)
                {
                    this.StoreError("There was a problem creating your account");
                    if (user.ID != Guid.Empty) _us.DeleteUser(user.ID);
                    return View(model);
                }
            }

            return View(model);
        }
Example #7
0
        public virtual ActionResult Email()
        {
            try
            {

                var model = new CreateAccountModel()
                {
                    AuthToken = string.Empty,
                    AuthTokenSecret = string.Empty,
                    AuthScreenname = string.Empty,
                    FirstName = string.Empty,
                    LastName = string.Empty,
                    DisplayProfileImage = Helpers.ResolveServerUrl(VirtualPathUtility.ToAbsolute("~/Public/images/signup/NoAvatar.png"), false),
                    ProfileImage = Helpers.ResolveServerUrl(VirtualPathUtility.ToAbsolute("~/Public/images/signup/NoAvatar.png"), false),
                    ServiceUserName = String.Empty,
                    AuthService = string.Empty,
                    InPopUp = InPopUp
                };

                return View(model);
            }
            catch (Exception)
            {
                this.StoreError("There was a problem. Please try again later.");
                return RedirectToAction("Signup", "join");
            }
        }
Example #8
0
        public virtual ActionResult Facebook(string returnUrl)
        {
            try
            {
                var client = new FacebookClient();
                var oauthResult = client.ParseOAuthCallbackUrl(Request.Url);

                // Build the Return URI form the Request Url
                var redirectUri = new UriBuilder(Url.Action("facebook", "join", new { InPopUp }, "http"));

                // Exchange the code for an access token
                dynamic result = client.Get("/oauth/access_token", new
                {
                    client_id = ConfigurationManager.AppSettings["FacebookAppId"],
                    redirect_uri = redirectUri.Uri.AbsoluteUri,
                    client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
                    code = oauthResult.Code,
                });

                // Read the auth values
                string accessToken = result.access_token;
                DateTime expires = DateTime.UtcNow.AddSeconds(Convert.ToDouble(result.expires));


                var fbClient = new FacebookClient(accessToken);

                dynamic facebookUser = fbClient.Get("me");

                if (facebookUser == null)
                {
                    this.StoreError("There was a problem connecting to your Facebook account");
                    return RedirectToAction("Signup", InPopUp);
                }

                //Check if this user already exists. If so login and redirect to the homepage
                var userId = CheckConnectedAccountUserExists(facebookUser.username, AuthenticationServices.FACEBOOK, accessToken, null);
                if (userId != Guid.Empty)
                {
                    CookieHelpers.WriteCookie("lc", "uid", userId.ToString());
                    RecordTheLogin(userId);

                    if (InPopUp)
                        return RedirectToAction("CloseAndRefresh", "Account");

                    //this.StoreInfo("The Facebook  account you used is already associated with an Epilogger account. We have logged you in.");
                    return RedirectToAction("Index", "Home", new { area = "" });
                }


                var model = new CreateAccountModel()
                {
                    AuthToken = accessToken,
                    AuthScreenname = facebookUser.username,
                    FirstName = facebookUser.first_name,
                    LastName = facebookUser.last_name,
                    DisplayProfileImage = FacebookHelper.GetProfilePictureWithSize(accessToken, "large"),
                    ProfileImage = FacebookHelper.GetProfilePicture(accessToken),
                    ServiceUserName = facebookUser.username,
                    AuthService = "facebook",
                    InPopUp = InPopUp
                };

                //Continue to Step 2
                return View(model);
            }
            catch (Exception)
            {
                this.StoreError("There was a problem connecting to your Facebook account");
                return RedirectToAction("Signup");
            }
        }