public void ProfilePageUpdate()
        {
            var page = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle          = Guid.NewGuid().ToString(),
                OwnerIdentifier = Guid.NewGuid(),
            };

            var core = new UserCore();

            core.Save(page);
            var newPage = new ProfilePage()
            {
                ExistingHandle        = page.Handle,
                Handle                = Guid.NewGuid().ToString(),
                ApplicationIdentifier = page.ApplicationIdentifier,
                OwnerIdentifier       = page.OwnerIdentifier,
            };

            core.Save(newPage);
            var get = core.Get(page);

            Assert.IsNull(get);
            get = core.Get(newPage);
            Assert.AreEqual <string>(newPage.Handle, get.Handle);
            Assert.AreEqual <Guid>(newPage.ApplicationIdentifier, get.ApplicationIdentifier);
            Assert.AreEqual <Guid>(newPage.OwnerIdentifier, get.OwnerIdentifier);
        }
        public ActionResult Get(UserPreference preference)
        {
            using (new PerformanceMonitor())
            {
                try
                {
                    if (null == preference)
                    {
                        return(this.Json(WebResponse.Bind((int)Fault.DataNotSpecified, "Preference not specified"), JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var user = User.Identity.Data();
                        var app  = Application.Current;
                        preference.User        = user;
                        preference.Application = app;

                        var saved = userCore.Get(preference);
                        saved.CanCreateApplication = appCore.PermitApplicationCreation(app, user);
                        return(this.Json(saved, JsonRequestBehavior.AllowGet));
                    }
                }
                catch (Exception ex)
                {
                    logger.Log(ex, EventTypes.Error, (int)Fault.Unknown);
                    return(this.Json(WebResponse.Bind((int)Fault.Unknown, ex.Message), JsonRequestBehavior.AllowGet));
                }
            }
        }
        public void UserPreferenceRoundTrip()
        {
            var core  = new UserCore();
            var pref  = this.Preference();
            var saved = core.Save(pref);

            Assert.AreEqual <Guid>(pref.User.Identifier, saved.User.Identifier);
            Assert.AreEqual <Guid>(pref.Application.Identifier, saved.Application.Identifier);
            Assert.AreEqual <Guid>(pref.CurrentApplication.Identifier, saved.CurrentApplication.Identifier);
            Assert.AreEqual <string>(pref.TimeZone.Id, saved.TimeZone.Id);
            Assert.AreEqual <string>(pref.TwitterHandle, saved.TwitterHandle);
            Assert.AreEqual <string>(pref.AbcHandle, saved.AbcHandle);
            Assert.AreEqual <string>(pref.GitHubHandle, saved.GitHubHandle);
            Assert.AreEqual <string>(pref.City, saved.City);
            Assert.AreEqual <string>(pref.Country, saved.Country);

            var got = core.Get(pref);

            Assert.AreEqual <Guid>(pref.User.Identifier, got.User.Identifier);
            Assert.AreEqual <Guid>(pref.Application.Identifier, got.Application.Identifier);
            Assert.AreEqual <Guid>(pref.CurrentApplication.Identifier, got.CurrentApplication.Identifier);
            Assert.AreEqual <string>(pref.TimeZone.Id, got.TimeZone.Id);
            Assert.AreEqual <string>(pref.TwitterHandle, got.TwitterHandle);
            Assert.AreEqual <string>(pref.AbcHandle, got.AbcHandle);
            Assert.AreEqual <string>(pref.GitHubHandle, got.GitHubHandle);
            Assert.AreEqual <string>(pref.City, got.City);
            Assert.AreEqual <string>(pref.Country, got.Country);
        }
        public JsonResult Activate(Guid userId)
        {
            if (userId == Guid.Empty)
            {
                return(Json(ResponseFactory.ErrorReponse));
            }

            var user = UserCore.Get(userId, new[] { nameof(datalayer.User.AspNetUser) });

            if (user == null)
            {
                return(Json(ResponseFactory.ErrorReponse));
            }

            user.AspNetUser.Status = 0;

            var updatedUser = AspNetUserCore.Update(user.AspNetUser);

            if (updatedUser == null)
            {
                return(Json(ResponseFactory.ErrorReponse));
            }

            return(Json(ResponseFactory.SuccessResponse));
        }
        public void GetUserPreferenceNullApplication()
        {
            var core = new UserCore();
            var pref = this.Preference();

            pref.Application = null;
            core.Get(pref);
        }
        public void GetUserPreferenceNullUser()
        {
            var core = new UserCore();
            var pref = this.Preference();

            pref.User = null;
            core.Get(pref);
        }
        public void GetUserPreferenceEmptyUserId()
        {
            var core = new UserCore();
            var pref = this.Preference();

            pref.User.Identifier = Guid.Empty;
            core.Get(pref);
        }
        public void GetUserApplicationEmptyUserIdentifier()
        {
            var core = new UserCore();
            var data = this.UserApp();

            data.User.Identifier = Guid.Empty;
            core.Get(data);
        }
        public void GetUserApplicationNullUser()
        {
            var core = new UserCore();
            var data = this.UserApp();

            data.User = null;
            core.Get(data);
        }
Example #10
0
        public ActionResult Profile()
        {
            using (new Service.PerformanceMonitor())
            {
                var user = User.Identity.Data();
                if (null != user)
                {
                    var preference = new UserPreference()
                    {
                        Application = Application.Current,
                        User        = user,
                    };

                    preference = userCore.Get(preference);
                    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,
                    };

                    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"));
                }
            }
        }
        public void UserPreferenceDoesntExist()
        {
            var core = new UserCore();
            var pref = this.Preference();

            var got = core.Get(pref);

            Assert.AreEqual <Guid>(pref.User.Identifier, got.User.Identifier);
            Assert.AreEqual <Guid>(pref.Application.Identifier, got.Application.Identifier);
            Assert.AreEqual <Guid>(pref.CurrentApplication.Identifier, got.CurrentApplication.Identifier);
            Assert.AreEqual <string>(pref.TimeZone.Id, got.TimeZone.Id);
        }
        public void GetProfilePageApplicationIdentifierEmpty()
        {
            var profile = new ProfilePage()
            {
                ApplicationIdentifier = Guid.Empty,
                Handle = StringHelper.ValidString(),
            };

            var core = new UserCore();

            core.Get(profile);
        }
        public void GetProfilePageHandleInvalid()
        {
            var profile = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle = StringHelper.NullEmptyWhiteSpace(),
            };

            var core = new UserCore();

            core.Get(profile);
        }
        public void GetUser()
        {
            var data  = new UserData(StringHelper.ValidString(), StringHelper.ValidString(), StringHelper.ValidString());
            var table = new AzureTable <UserData>(ServerConfiguration.Default);

            table.AddEntity(data);

            var core    = new UserCore();
            var userApp = this.UserApp();

            userApp.User.Identifier        = data.Id;
            userApp.Application.Identifier = data.ApplicationId;
            var user = core.Get(userApp);

            Assert.AreEqual <Guid>(data.Id, user.Identifier);
            Assert.AreEqual <string>(data.Email, user.Email);
            Assert.AreEqual <string>(data.UserName, user.UserName);
        }
        public void RoundTripProfilePage()
        {
            var page = new ProfilePage()
            {
                ApplicationIdentifier = Guid.NewGuid(),
                Handle          = Guid.NewGuid().ToString(),
                OwnerIdentifier = Guid.NewGuid(),
            };

            var core = new UserCore();

            core.Save(page);
            var get = core.Get(page);

            Assert.IsNotNull(get);
            Assert.AreEqual <string>(page.Handle, get.Handle);
            Assert.AreEqual <Guid>(page.ApplicationIdentifier, get.ApplicationIdentifier);
            Assert.AreEqual <Guid>(page.OwnerIdentifier, get.OwnerIdentifier);
        }
        /// <summary>
        /// Get Preference
        /// </summary>
        /// <param name="appId">Application Identifier</param>
        /// <param name="userId">User Identifier</param>
        /// <returns>User Preference</returns>
        private static UserPreference GetPreference(Guid appId, Guid userId)
        {
            using (new PerformanceMonitor())
            {
                var app = new Application()
                {
                    Identifier = appId,
                };
                var user = new User()
                {
                    Identifier = userId,
                };
                var pref = new UserPreference()
                {
                    Application = app,
                    User        = user,
                };

                var core = new UserCore();
                return(core.Get(pref));
            }
        }
        public ActionResult DeleteUserRole(UserRole userRole)
        {
            using (new PerformanceMonitor())
            {
                if (null == userRole)
                {
                    return(this.Json(WebResponse.Bind((int)Fault.DataNotSpecified, "User Role not specified."), JsonRequestBehavior.AllowGet));
                }
                else
                {
                    try
                    {
                        var userCore = new UserCore();
                        var userId   = new User()
                        {
                            Identifier = userRole.UserIdentifier,
                        };
                        var userApp = new UserApplication()
                        {
                            User        = userId,
                            Application = Application.Current,
                        };
                        var user = userCore.Get(userApp);

                        var roles = new AzureRoleProvider();
                        roles.RemoveUserFromRole(user.UserName, userRole.RoleName);

                        return(this.Json(new WebResponse(), JsonRequestBehavior.AllowGet));
                    }
                    catch (Exception ex)
                    {
                        logger.Log(ex, EventTypes.Error, (int)Fault.Unknown);
                        return(this.Json(WebResponse.Bind((int)Fault.Unknown, ex.Message), JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }
        public ActionResult  Details(Guid appId)
        {
            using (new PerformanceMonitor())
            {
                var app = new Application()
                {
                    Identifier = appId,
                };

                try
                {
                    var canCreateApplication = this.CanCreateAnApplication();
                    if (canCreateApplication && Guid.Empty == appId)
                    {
                        var newApp = new ApplicationDetailsModel()
                        {
                            ApplicationId = Guid.NewGuid(),
                            IsValid       = true,
                            New           = true,
                            Deleted       = false,
                            Active        = true,
                            ValidUntil    = DateTime.UtcNow.AddYears(1),
                        };

                        newApp.PublicKey    = newApp.ApplicationId.ToAscii85().GetHexMD5();
                        this.ViewData.Model = newApp;
                    }
                    else if (Guid.Empty != appId && appCore.UserIsAssociated(User.Identity.Editor(), app))
                    {
                        var info = new ApplicationInformation()
                        {
                            Identifier = appId,
                        };
                        var appInfo = appCore.Get(info);
                        if (null != appInfo)
                        {
                            var model = appInfo.Convert();

                            try
                            {
                                if (Guid.Empty != appInfo.OwnerId)
                                {
                                    var userCore    = new UserCore();
                                    var application = new Application()
                                    {
                                        Identifier = appId,
                                    };
                                    var user = new User()
                                    {
                                        Identifier = appInfo.OwnerId,
                                    };
                                    var userApp = new UserApplication()
                                    {
                                        Application = application,
                                        User        = user,
                                    };
                                    var userLoaded = userCore.Get(userApp);
                                    model.User = userLoaded.Convert().Convert();
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Log(ex, EventTypes.Error, (int)Fault.Unknown);
                            }

                            this.ViewData.Model = model;
                        }
                    }
                    else
                    {
                        return(this.RedirectToAction("Application"));
                    }

                    ViewBag.CanCreateAnApplication = canCreateApplication;
                    return(this.View());
                }
                catch (Exception ex)
                {
                    log.Log(ex, EventTypes.Error, (int)Fault.Unknown);
                    return(View());
                }
            }
        }
Example #19
0
        /// <summary>
        /// Default Page
        /// </summary>
        /// <remarks>
        /// GET: /
        /// </remarks>
        /// <returns>Action Result</returns>
        public ActionResult Index(string username)
        {
            using (new PerformanceMonitor())
            {
                if (!string.IsNullOrWhiteSpace(username))
                {
                    var page = new ProfilePage()
                    {
                        Handle = username,
                        ApplicationIdentifier = Application.Current.Identifier,
                    };

                    try
                    {
                        var core = new UserCore();
                        page = core.Get(page);
                        if (null != page)
                        {
                            var user = new User()
                            {
                                Identifier = page.OwnerIdentifier,
                            };

                            var userApp = new UserApplication()
                            {
                                Application = Application.Current,
                                User        = user,
                            };

                            var userCore = new UserCore();
                            user = userCore.GetByIdentifier(userApp);
                            if (null != user)
                            {
                                var publicProfile = user.Convert().Convert();

                                var preference = new UserPreference()
                                {
                                    Application = Application.Current,
                                    User        = user,
                                };

                                preference = userCore.Get(preference);

                                publicProfile.Set(preference);

                                if (!string.IsNullOrWhiteSpace(publicProfile.TwitterHandle))
                                {
                                    try
                                    {
                                        var twitter = new TwitterSource();
                                        publicProfile.Tweets = twitter.ByUser(publicProfile.TwitterHandle, 10).ToList();
                                    }
                                    catch (Exception ex)
                                    {
                                        log.Log(ex, EventTypes.Warning, (int)Fault.TwitterFailure);
                                    }
                                }
                                return(this.View(publicProfile));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Log(ex, EventTypes.Warning, (int)ServiceFault.Empty);
                    }
                }

                return(this.RedirectToAction("Index", "Home"));
            }
        }
        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"));
        }
        /// <summary>
        /// Default Page
        /// </summary>
        /// <remarks>
        /// GET: /
        /// </remarks>
        /// <returns>Action Result</returns>
        public ActionResult Index(string username)
        {
            if (!string.IsNullOrWhiteSpace(username))
            {
                var page = new ProfilePage()
                {
                    Handle = username,
                    ApplicationIdentifier = Application.Default.Identifier,
                };

                try
                {
                    var core = new UserCore();
                    page = core.Get(page);
                    if (null != page)
                    {
                        var user = new User()
                        {
                            Identifier = page.OwnerIdentifier,
                        };

                        var userApp = new UserApplication()
                        {
                            Application = Application.Default,
                            User        = user,
                        };

                        var userCore = new UserCore();
                        user = userCore.GetByIdentifier(userApp);
                        if (null != user)
                        {
                            var temp = user.Convert();
                            temp.Points = page.Points;
                            var publicProfile = temp.Convert();

                            var preference = new UserPreference()
                            {
                                Application = Application.Default,
                                User        = user,
                            };

                            preference = userCore.Get(preference);

                            publicProfile.Set(preference);

                            if (!string.IsNullOrWhiteSpace(publicProfile.TwitterHandle))
                            {
                                try
                                {
                                    var twitter = new TwitterSource();
                                    publicProfile.Tweets = twitter.ByUser(publicProfile.TwitterHandle, 10).ToList();
                                }
                                catch (Exception ex)
                                {
                                    logger.Log(ex, EventTypes.Warning, 999);
                                }
                            }

                            this.ViewBag.Gravatar      = publicProfile.Gravatar;
                            this.ViewBag.AbcHandle     = publicProfile.AbcHandle.ToLower();
                            this.ViewBag.GithubHandle  = publicProfile.GitHubHandle;
                            this.ViewBag.TwitterHandle = publicProfile.TwitterHandle;
                            return(this.View(publicProfile));
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Log(ex, EventTypes.Warning, 999);
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
        public void GetProfilePagePageNull()
        {
            var core = new UserCore();

            core.Get((ProfilePage)null);
        }
        public void GetUserPreferenceNull()
        {
            var core = new UserCore();

            core.Get((UserPreference)null);
        }
        public void GetUserApplicationNull()
        {
            var core = new UserCore();

            core.Get((UserApplication)null);
        }