protected static bool ValidateAuthentication(bool throwWebFaultException, out ProfileDetails profileDetails) { LiveLoginResult result = SessionWrapper.Get<LiveLoginResult>("LiveConnectResult"); if (result != null && result.Status == LiveConnectSessionStatus.Connected) { profileDetails = SessionWrapper.Get<ProfileDetails>("ProfileDetails"); return true; } profileDetails = new ProfileDetails(); return false; }
public long CreateProfile(ProfileDetails profileDetails) { // Make sure communityDetails is not null this.CheckNotNull(() => new { profileDetails }); // Check if the user already exists in the Layerscape database. User existingUser = _userRepository.GetItem(u => u.LiveID == profileDetails.PUID); if (existingUser != null) { return existingUser.UserID; } else { // 1. Add Community details to the community object. var user = new User(); Mapper.Map(profileDetails, user); user.JoinedDateTime = DateTime.UtcNow; user.LastLoginDatetime = DateTime.UtcNow; // While creating the user, IsDeleted to be false always. user.IsDeleted = false; // Add the user to the repository _userRepository.Add(user); // Save all the changes made. _userRepository.SaveChanges(); return user.UserID; } }
protected async Task<LiveLoginResult> TryAuthenticateFromHttpContext(ICommunityService communityService, INotificationService notificationService) { var svc = new LiveIdAuth(); var result = await svc.Authenticate(); if (result.Status == LiveConnectSessionStatus.Connected) { var client = new LiveConnectClient(result.Session); SessionWrapper.Set("LiveConnectClient", client); SessionWrapper.Set("LiveConnectResult", result); SessionWrapper.Set("LiveAuthSvc", svc); var getResult = await client.GetAsync("me"); var jsonResult = getResult.Result as dynamic; var profileDetails = ProfileService.GetProfile(jsonResult.id); if (profileDetails == null) { profileDetails = new ProfileDetails(jsonResult); // While creating the user, IsSubscribed to be true always. profileDetails.IsSubscribed = true; // When creating the user, by default the user type will be of regular. profileDetails.UserType = UserTypes.Regular; profileDetails.ID = ProfileService.CreateProfile(profileDetails); // This will used as the default community when user is uploading a new content. // This community will need to have the following details: var communityDetails = new CommunityDetails { CommunityType = CommunityTypes.User, // 1. This community type should be User CreatedByID = profileDetails.ID, // 2. CreatedBy will be the new USER. IsFeatured = false, // 3. This community is not featured. Name = Resources.UserCommunityName, // 4. Name should be NONE. AccessTypeID = (int) AccessType.Private, // 5. Access type should be private. CategoryID = (int) CategoryType.GeneralInterest // 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null. }; // 7. Create the community communityService.CreateCommunity(communityDetails); // Send New user notification. notificationService.NotifyNewEntityRequest(profileDetails, HttpContext.Request.Url.GetServerLink()); } SessionWrapper.Set<long>("CurrentUserID", profileDetails.ID); SessionWrapper.Set<string>("CurrentUserProfileName", profileDetails.FirstName + " " + profileDetails.LastName); SessionWrapper.Set("ProfileDetails", profileDetails); SessionWrapper.Set("AuthenticationToken", result.Session.AuthenticationToken); } return result; }
public IEnumerable<ProfileDetails> GetProfiles(IEnumerable<long> users) { var profileDetails = new List<ProfileDetails>(); Expression<Func<User, bool>> condition = (user) => (users.Contains(user.UserID)); var userDetails = _userRepository.GetItems(condition, null, false); if (userDetails != null) { foreach (var userDetail in userDetails) { var profileDetail = new ProfileDetails(); Mapper.Map(userDetail, profileDetail); profileDetails.Add(profileDetail); } } return profileDetails; }
public bool UpdateProfile(ProfileDetails profile) { var status = false; var userDetails = _userRepository.GetItem(user => user.UserID == profile.ID); if (userDetails != null) { try { // Only in case if new Picture is uploaded, move it from temporary container. if (userDetails.PictureID != profile.PictureID) { profile.PictureID = MoveThumbnail(profile.PictureID); } // Set About me and Affiliation details userDetails.Affiliation = profile.Affiliation; userDetails.AboutMe = profile.AboutMe; userDetails.FirstName = profile.FirstName; userDetails.LastName = profile.LastName; userDetails.IsSubscribed = profile.IsSubscribed; userDetails.PictureID = profile.PictureID; userDetails.LastLoginDatetime = profile.LastLogOnDatetime; // Add the user to the repository _userRepository.Update(userDetails); // Save all the changes made. _userRepository.SaveChanges(); status = true; } catch (Exception) { // Delete Uploaded Thumbnail DeleteThumbnail(profile.PictureID); throw; } } return status; }
public ProfileDetails GetProfile(string puid) { ProfileDetails profileDetails = null; var userDetails = _userRepository.GetItem(user => user.LiveID == puid); // Check if the user details is present. // DO NOT use CheckNotNull since GetProfile should not throw exception. if (userDetails != null) { profileDetails = new ProfileDetails(); Mapper.Map(userDetails, profileDetails); // Set the consumed size profileDetails.ConsumedSize = _contentsViewRepository.GetConsumedSize(userDetails.UserID); } return profileDetails; }
/// <summary> /// Gets the user profile from USER ID /// </summary> /// <param name="userId">User profile ID</param> /// <returns>ProfileDetails object</returns> public ProfileDetails GetProfile(long userId) { var profileDetails = new ProfileDetails(); var userDetails = _userRepository.GetItem(user => user.UserID == userId, "UserType"); // Check if the user details is present. this.CheckNotNull(() => new { userDetails }); Mapper.Map(userDetails, profileDetails); // Set the consumed size profileDetails.ConsumedSize = _contentsViewRepository.GetConsumedSize(userId); return profileDetails; }
public JsonResult Save(long profileId, string affiliation, string aboutMe, bool isSubscribed, Guid? profileImageId, string profileName) { if (profileId == CurrentUserId) { var profileDetails = new ProfileDetails() { ID = profileId, Affiliation = Server.UrlDecode(affiliation), AboutMe = aboutMe, IsSubscribed = isSubscribed, PictureID = profileImageId }; profileName = Server.UrlDecode(profileName); if (!string.IsNullOrWhiteSpace(profileName)) { if (profileName.Length > 50) { profileDetails.FirstName = profileName.Substring(0, 50); profileDetails.LastName = profileName.Substring(50); } else { profileDetails.FirstName = profileName; profileDetails.LastName = string.Empty; } } ProfileService.UpdateProfile(profileDetails); // This will make sure that the latest name from DB will be fetched again. SessionWrapper.Set<string>("CurrentUserProfileName", null); return new JsonResult { Data = GetProfile(CurrentUserId) }; } return new JsonResult { Data = "UserId does not match current user" }; }
/// <summary> /// This function is used to get all profiles in the database excluding the current user. /// This operation can be only performed by a site admin. /// </summary> /// <param name="userId">ID the of the current user.</param> /// <returns>List of all profile in database.</returns> public async Task<IEnumerable<ProfileDetails>> GetAllProfiles(long userId) { var profiles = new List<ProfileDetails>(); if (_userRepository.IsSiteAdmin(userId)) { var users = _userRepository.GetItems(user => user.UserID != userId, user => user.LastName, false); foreach (var item in users) { var profileDetails = new ProfileDetails(); Mapper.Map(item, profileDetails); profiles.Add(profileDetails); } } return profiles; }
private long CreateCollection(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity) { // Get name/ tags/ category from Tour. var collectionDoc = new XmlDocument(); ContentDetails content = null; // NetworkStream is not Seek able. Need to load into memory stream so that it can be sought using (Stream writablefileContent = new MemoryStream()) { fileContent.CopyTo(writablefileContent); writablefileContent.Position = 0; content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity); writablefileContent.Seek(0, SeekOrigin.Begin); collectionDoc = collectionDoc.SetXmlFromWtml(writablefileContent); } if (collectionDoc != null) { content.Name = collectionDoc.GetAttributeValue("Folder", "Name"); } var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService; var contentId = content.ID = contentService.CreateContent(content); if (contentId > 0) { var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService; notificationService.NotifyNewEntityRequest(content, BaseUri() + "/"); } return contentId; }
private ContentDetails GetContentDetail(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity) { var content = new ContentDetails(); var fileDetail = UpdateFileDetails(filename, fileContent); content.ContentData = fileDetail; content.CreatedByID = profileDetails.ID; // By Default the access type will be private. content.AccessTypeID = (int)AccessType.Public; // Get the Category/Tags from Parent. content.ParentID = parentCommunity.ID; content.ParentType = parentCommunity.CommunityType; content.CategoryID = parentCommunity.CategoryID; return content; }
private long CreateTour(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity) { var tourDoc = new XmlDocument(); ContentDetails content = null; // NetworkStream is not Seek able. Need to load into memory stream so that it can be sought using (Stream writablefileContent = new MemoryStream()) { fileContent.CopyTo(writablefileContent); writablefileContent.Position = 0; content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity); writablefileContent.Position = 0; tourDoc = tourDoc.SetXmlFromTour(writablefileContent); } if (tourDoc != null) { // Note that the spelling of Description is wrong because that's how WWT generates the WTT file. content.Name = tourDoc.GetAttributeValue("Tour", "Title"); content.Description = tourDoc.GetAttributeValue("Tour", "Descirption"); content.DistributedBy = tourDoc.GetAttributeValue("Tour", "Author"); content.TourLength = tourDoc.GetAttributeValue("Tour", "RunTime"); } var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService; var contentId = content.ID = contentService.CreateContent(content); if (contentId > 0) { var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService; notificationService.NotifyNewEntityRequest(content, BaseUri() + "/"); } return contentId; }
private long CreateContent(string filename, Stream fileContent, ProfileDetails profileDetails, CommunityDetails parentCommunity) { ContentDetails content = null; // No need to get into a memory stream as the stream is sent as is and need not be loaded using (Stream writablefileContent = new MemoryStream()) { fileContent.CopyTo(writablefileContent); writablefileContent.Position = 0; content = GetContentDetail(filename, writablefileContent, profileDetails, parentCommunity); content.Name = Path.GetFileNameWithoutExtension(filename); } var contentService = DependencyResolver.Current.GetService(typeof(IContentService)) as IContentService; var contentId = content.ID = contentService.CreateContent(content); if (contentId > 0) { var notificationService = DependencyResolver.Current.GetService(typeof(INotificationService)) as INotificationService; notificationService.NotifyNewEntityRequest(content, BaseUri() + "/"); } return contentId; }
public async Task<bool> RegisterUser() { var profileDetails = await ValidateAuthentication(); if (profileDetails == null) { var svc = new LiveIdAuth(); dynamic jsonResult = svc.GetMeInfo(System.Web.HttpContext.Current.Request.Headers["LiveUserToken"]); profileDetails = new ProfileDetails(jsonResult); // While creating the user, IsSubscribed to be true always. profileDetails.IsSubscribed = true; // When creating the user, by default the user type will be of regular. profileDetails.UserType = UserTypes.Regular; profileDetails.ID = ProfileService.CreateProfile(profileDetails); // This will used as the default community when user is uploading a new content. // This community will need to have the following details: var communityDetails = new CommunityDetails { CommunityType = CommunityTypes.User,// 1. This community type should be User CreatedByID = profileDetails.ID,// 2. CreatedBy will be the new USER. IsFeatured = false,// 3. This community is not featured. Name = Resources.UserCommunityName,// 4. Name should be NONE. AccessTypeID = (int) AccessType.Private,// 5. Access type should be private. CategoryID = (int) CategoryType.GeneralInterest// 6. Set the category ID of general interest. We need to set the Category ID as it is a foreign key and cannot be null. }; // 7. Create the community _communityService.CreateCommunity(communityDetails); // Send New user notification. _notificationService.NotifyNewEntityRequest(profileDetails, HttpContext.Request.Url.GetServerLink()); } else { throw new WebFaultException<string>("User already registered", HttpStatusCode.BadRequest); } return true; }
private void SendNewUserMail(ProfileDetails profileDetails, string server) { try { // Send Mail. var request = new NewEntityRequest(); request.EntityType = EntityType.User; request.EntityID = profileDetails.ID; request.EntityName = profileDetails.FirstName + " " + profileDetails.LastName; request.EntityLink = string.Format(CultureInfo.InvariantCulture, "{0}Profile/Index/{1}", server, profileDetails.ID); SendMail(request); } catch (Exception) { // Ignore all exceptions. } }
/// <summary> /// Notify the user about the new User. /// </summary> /// <param name="profileDetails">User details</param> /// <param name="server">Server details.</param> public void NotifyNewEntityRequest(ProfileDetails profileDetails, string server) { if (Constants.CanSendNewEntityMail) { SendNewUserMail(profileDetails, server); } }