public ActionResult Edit(FormCollection collection)
        {
            var twitterHandle = collection["TwitterHandle"];

            if (string.IsNullOrWhiteSpace(twitterHandle))
            {
                return(base.RedirectToAction("Index", "Home"));
            }
            else
            {
                var source     = new DomainSource();
                var user       = source.GetUserByEmail(Application.Default.Identifier, base.User.Identity.Name);
                var preference = new UserPreference()
                {
                    TwitterHandle = twitterHandle,
                    User          = user.Convert(),
                    Application   = Application.Default,
                };

                var core = new UserCore();
                core.Save(preference);

                return(this.Edit());
            }
        }
Exemplo n.º 2
0
        public User GetByEmail(UserApplication userApp)
        {
            Contract.Requires <ArgumentNullException>(null != userApp);
            Contract.Requires <ArgumentNullException>(null != userApp.Application);
            Contract.Requires <ArgumentNullException>(null != userApp.User);
            Contract.Requires <ArgumentOutOfRangeException>(Guid.Empty != userApp.Application.Identifier);
            Contract.Requires <ArgumentOutOfRangeException>(!string.IsNullOrWhiteSpace(userApp.User.Email));

            var source   = new DomainSource();
            var userData = source.GetUserByEmail(userApp.Application.Identifier, userApp.User.Email);

            return(userData == null ? (User)null : userData.Convert());
        }
Exemplo n.º 3
0
        private bool Login(GitHubProfile profile)
        {
            var newUser  = false;
            var register = new RegisterModel()
            {
                Email          = profile.Email,
                NameIdentifier = string.Format("github{0}", profile.Id),
                UserName       = profile.Name,
            };

            var      source = new DomainSource();
            UserData user   = null;

            if (!string.IsNullOrWhiteSpace(register.NameIdentifier) && null != (user = source.GetUserByNameIdentifier(Application.Default.Identifier, register.NameIdentifier)))
            {
                user.LastLoggedInOn = DateTime.UtcNow;
                user.LastActivityOn = DateTime.UtcNow;

                source.Update(user);
            }
            else if (!string.IsNullOrWhiteSpace(register.Email) && null != (user = source.GetUserByEmail(Application.Default.Identifier, register.Email)))
            {
                user.LastLoggedInOn = DateTime.UtcNow;
                user.LastActivityOn = DateTime.UtcNow;
                user.NameIdentifier = register.NameIdentifier;

                source.Update(user);
            }
            else
            {
                var provider = new TableMembershipProvider();
                MembershipCreateStatus status;
                provider.CreateUser(register.UserName, Guid.NewGuid().ToString(), register.Email, null, null, true, register.NameIdentifier, out status);
                if (status == MembershipCreateStatus.Success)
                {
                    log.Log("New user signed up.");
                    newUser = true;
                }
                else
                {
                    log.Log(string.Format("New user failed to signed up; status: '{0}'", status));
                }
            }

            FormsAuthentication.SetAuthCookie(register.Email, true);

            return(newUser);
        }
Exemplo n.º 4
0
        public ActionResult AddUserToTribe(string tribe)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(tribe))
                {
                    return(this.Json(WebResponse.Bind((int)Fault.Unknown, "Tribe must be specified."), JsonRequestBehavior.AllowGet));
                }

                var source = new DomainSource();
                var user   = source.GetUserByEmail(Application.Default.Identifier, base.User.Identity.Name);
                var core   = new UserCore();
                core.Save(user.Convert(), tribe);
            }
            catch (Exception ex)
            {
                logger.Log(ex, EventTypes.Warning, 999);
                return(this.Json(WebResponse.Bind((int)Fault.Unknown, ex.Message), JsonRequestBehavior.AllowGet));
            }
            return(View());
        }
        public void GetUserByEmail()
        {
            var source = new DomainSource();
            var user   = User();

            user.Email = StringHelper.ValidString();
            source.Insert(user);

            var saved = source.GetUserByEmail(user.ApplicationId, user.Email);

            Assert.IsNotNull(saved);
            Assert.AreEqual <DateTime>(saved.CreatedOn, user.CreatedOn);
            Assert.AreEqual <DateTime>(saved.LastLoggedInOn, user.LastLoggedInOn);
            Assert.AreEqual <DateTime>(saved.LastActivityOn, user.LastActivityOn);
            Assert.AreEqual <DateTime>(saved.PasswordLastChangedOn, user.PasswordLastChangedOn);
            Assert.AreEqual <string>(saved.Email, user.Email);
            Assert.AreEqual <string>(saved.OpenId, user.OpenId);
            Assert.AreEqual <string>(saved.UserName, user.UserName);
            Assert.AreEqual <int>(saved.RoleValue, user.RoleValue);
            Assert.AreEqual <bool>(saved.IsApproved, user.IsApproved);
            Assert.AreEqual <bool>(saved.IsLockedOut, user.IsLockedOut);
            Assert.AreEqual <DateTime>(saved.LastLockedOutOn, user.LastLockedOutOn);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Register user on site
        /// </summary>
        /// <param name="userIdentity">user Identity</param>
        /// <returns>New User</returns>
        private bool Register(IIdentity userIdentity)
        {
            using (new Service.PerformanceMonitor())
            {
                if (userIdentity.IsAuthenticated)
                {
                    var identity = (IClaimsIdentity)userIdentity;

                    var register = new RegisterModel()
                    {
                        Email          = User.Identity.EmailAddress(),
                        NameIdentifier = User.Identity.NameIdentifier(),
                        UserName       = identity.Name,
                    };

                    var      source = new DomainSource();
                    UserData user   = null;
                    if (!string.IsNullOrWhiteSpace(register.NameIdentifier) && null != (user = source.GetUserByNameIdentifier(ServerConfiguration.ApplicationIdentifier, register.NameIdentifier)))
                    {
                        user.LastLoggedInOn = DateTime.UtcNow;
                        user.LastActivityOn = DateTime.UtcNow;

                        source.Update(user);
                    }
                    else if (!string.IsNullOrWhiteSpace(register.Email) && null != (user = source.GetUserByEmail(ServerConfiguration.ApplicationIdentifier, register.Email)))
                    {
                        user.LastLoggedInOn = DateTime.UtcNow;
                        user.LastActivityOn = DateTime.UtcNow;
                        user.NameIdentifier = register.NameIdentifier;

                        source.Update(user);
                    }
                    else
                    {
                        var provider = new TableMembershipProvider();
                        MembershipCreateStatus status;
                        provider.CreateUser(register.UserName, Guid.NewGuid().ToString(), register.Email, null, null, true, register.NameIdentifier, out status);
                        if (status == MembershipCreateStatus.Success)
                        {
                            log.Log("New user signed up.");
                            return(true);
                        }
                        else
                        {
                            log.Log("New user failed to signed up; status: '{0}'".FormatWithCulture(status));
                        }
                    }
                }
            }

            return(false);
        }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool approved, object providerUserKey, out MembershipCreateStatus status)
        {
            using (new PerformanceMonitor())
            {
                MembershipUser membership = null;
                status = MembershipCreateStatus.UserRejected;

                UserData userValidation = null;
                if (!string.IsNullOrWhiteSpace(email))
                {
                    userValidation = source.GetUserByEmail(Application.Default.Identifier, email);
                    if (null != userValidation)
                    {
                        status = MembershipCreateStatus.DuplicateEmail;
                    }
                }

                if (!string.IsNullOrWhiteSpace(username))
                {
                    userValidation = source.GetUserByEmail(Application.Default.Identifier, username);
                    if (null != userValidation)
                    {
                        status = MembershipCreateStatus.DuplicateUserName;
                    }
                }

                if (null == userValidation)
                {
                    userValidation = source.GetUserByNameIdentifier(Application.Default.Identifier, providerUserKey.ToString());
                    if (null != userValidation)
                    {
                        status = MembershipCreateStatus.DuplicateProviderUserKey;
                    }
                    else
                    {
                        var user = new UserData(email, providerUserKey.ToString(), username)
                        {
                            RoleValue = (int)TableMembershipProvider.DetermineRoleType(email),
                        };

                        source.Insert(user);

                        var returnedUser = source.GetUserById(Application.Default.Identifier, user.Id);
                        if (null == returnedUser)
                        {
                            status = MembershipCreateStatus.ProviderError;
                        }
                        else if (!returnedUser.IsApproved)
                        {
                            status = MembershipCreateStatus.UserRejected;
                        }
                        else if (returnedUser.IsLockedOut)
                        {
                            status = MembershipCreateStatus.UserRejected;
                        }
                        else
                        {
                            status     = MembershipCreateStatus.Success;
                            membership = new MembershipUser(ProviderName, returnedUser.UserName, returnedUser.NameIdentifier, returnedUser.Email, passwordQuestion, string.Empty, returnedUser.IsApproved, returnedUser.IsLockedOut, returnedUser.CreatedOn, returnedUser.LastLoggedInOn, returnedUser.LastActivityOn, returnedUser.PasswordLastChangedOn, returnedUser.LastLockedOutOn);

                            logger.Log("New user signed up.");
                        }
                    }
                }

                return(membership);
            }
        }
        public ActionResult Edit()
        {
            try
            {
                var source = new DomainSource();
                var user   = source.GetUserByEmail(Application.Default.Identifier, base.User.Identity.Name);
                if (null != user)
                {
                    var preference = new UserPreference()
                    {
                        Application = Application.Default,
                        User        = user.Convert(),
                    };

                    var userCore = new UserCore();
                    preference = userCore.Get(preference);
                    var page = new ProfilePage()
                    {
                        ApplicationIdentifier = Application.Default.Identifier,
                        Handle = preference.AbcHandle,
                    };
                    page = userCore.Get(page);
                    var profile = new UserProfile()
                    {
                        CreatedOn = user.CreatedOn,
                        Gravatar  = string.IsNullOrWhiteSpace(user.Email) ? null : user.Email.GetHexMD5(),
                        UserName  = user.UserName,
                        Email     = user.Email,
                        TimeZone  = preference.TimeZone,
                        MaximumAllowedApplications   = preference.MaximumAllowedApplications,
                        CurrentApplicationIdentifier = preference.CurrentApplication == null ? Guid.Empty : preference.CurrentApplication.Identifier,
                        TwitterHandle  = preference.TwitterHandle,
                        AbcHandle      = preference.AbcHandle,
                        City           = preference.City,
                        Country        = preference.Country,
                        GitHubHandle   = preference.GitHubHandle,
                        GitId          = page.GitId,
                        GitAvatarUrl   = page.GitAvatarUrl,
                        GitGravatarId  = page.GitGravatarId,
                        GitUrl         = page.GitUrl,
                        GitBlog        = page.GitBlog,
                        GitHireable    = page.GitHireable,
                        GitBiography   = page.GitBiography,
                        GitPublicGists = page.GitPublicGists,
                        GitPublicRepos = page.GitPublicRepos,
                        GitFollowers   = page.GitFollowers,
                        GitFollowing   = page.GitFollowing,
                        GitHtmlUrl     = page.GitHtmlUrl,
                        GitCreatedAt   = page.GitCreatedAt,
                        GitType        = page.GitType,
                        GitAccessToken = page.GitAccessToken,
                        GitCode        = page.GitCode,
                        Word           = page.Word,
                    };

                    profile.TimeZones = TimeZoneInfo.GetSystemTimeZones().Select(tz => new SelectListItem()
                    {
                        Text     = tz.DisplayName,
                        Value    = tz.Id,
                        Selected = tz.Id == profile.TimeZone.Id,
                    });

                    return(View(profile));
                }
                else
                {
                    return(base.RedirectToAction("Index", "Home"));
                }
            }
            catch (Exception ex)
            {
                logger.Log(ex, EventTypes.Warning, 999);
            }

            return(base.RedirectToAction("Index", "Home"));
        }
        public void GetUserByEmailInvalidApplicationId()
        {
            var source = new DomainSource();

            source.GetUserByEmail(Guid.Empty, StringHelper.ValidString());
        }
        public void GetUserByEmailInvalidEmail()
        {
            var source = new DomainSource();

            source.GetUserByEmail(Guid.NewGuid(), StringHelper.NullEmptyWhiteSpace());
        }