public static JqGridResponse Edit(EditMemberManagementVM model, ProviderCurrentMember currentMember) { JqGridResponse aResponse = new JqGridResponse(); ProviderMember aMember = new ProviderMember(model.Id); if (currentMember.CanEdit(aMember)) { aMember.IsArticleAdmin = model.IsArticleAdmin; aMember.IsBanned = model.IsBanned; aMember.IsCategoryAdmin = model.IsCategoryAdmin; aMember.IsMasterAdmin = model.IsMasterAdmin; aMember.IsMemberAdmin = model.IsMemberAdmin; aMember.IsSuperAdmin = model.IsSuperAdmin; try { aMember.Save(); aResponse.Success = true; } catch (Exception caughtException) { aResponse.Success = false; aResponse.Message = ErrorStrings.OPERATION_FAILED; } } else { aResponse.Success = false; aResponse.Message = ErrorStrings.OPERATION_NO_RIGHTS; } return aResponse; }
/// <summary> /// Function to update or create an member account with openId information. /// </summary> /// <param name="openId">openId of the member account we wish to create or update</param> /// <param name="email">e-mail information of the member</param> /// <param name="host">the open id provider hostname (www.google.com for instance)</param> /// <returns>true if the member was successfully updated/created.</returns> public static bool UpdateMemberOpenId(string openId, MailAddress email, string host) { // check if this member exists already ProviderMember aMember; ProviderEmail anEmailId = new ProviderEmail(); ProviderOpenId anOpenId = new ProviderOpenId(); // Prepare the e-mail if (email != null) { if (!anEmailId.Load(email.Address)) { anEmailId.CreateDate = DateTime.UtcNow; anEmailId.EditDate = DateTime.UtcNow; anEmailId.Email = email; anEmailId.IsValidated = true; } } // Prepare the openId if (!anOpenId.Load(openId)) { anOpenId.CreateDate = DateTime.UtcNow; anOpenId.EditDate = DateTime.UtcNow; anOpenId.OpenId = openId; anOpenId.DisplayName = host; anOpenId.IsValidated = true; } // TODO: my gut tells me these if statements can possibly be reduced to something simpler if (anOpenId.IsNew && anEmailId.IsNew) { // This person doesn't exist yet so create them aMember = new ProviderMember(); aMember.CreateDate = DateTime.UtcNow; aMember.EditDate = DateTime.UtcNow; aMember.Save(); // create the e-mail if (email != null) { anEmailId.MemberId = aMember.Id.Value; anEmailId.Save(); } // create the openId anOpenId.MemberId = aMember.Id.Value; anOpenId.Save(); } else if (!anOpenId.IsNew && anEmailId.IsNew && email != null) { // this person has an account already with an open id but no e-mail so just add the e-mail to the account aMember = new ProviderMember(anOpenId.MemberId); aMember.EditDate = DateTime.UtcNow; aMember.Save(); anEmailId.MemberId = aMember.Id.Value; anEmailId.Save(); } else if (anOpenId.IsNew && !anEmailId.IsNew) { // this person has an account already with an e-mail but no openId so just add the openId to the account aMember = new ProviderMember(anEmailId.MemberId); aMember.EditDate = DateTime.UtcNow; aMember.Save(); anOpenId.MemberId = aMember.Id.Value; anOpenId.Save(); } else if ( !anOpenId.IsNew && !anEmailId.IsNew && anOpenId.MemberId != anEmailId.MemberId) { // TODO: Crap two different accounts! // Do nothing for now but what we really want to do is try and merge the two accounts (with user permission of course). } else { // No updates are required } return true; }
public static bool SavePersonalInfo(PersonalInfoVM model, ProviderMember aMember) { // save username and bio. everything else is saved asynchronously through other methods aMember.Bio = model.Bio; aMember.Save(); if (string.IsNullOrWhiteSpace(model.UserName)) { // If someone blanked out their username then delete it. // Otherwise it was just blank so do nothing. if (aMember.UserNames.Count > 0) { aMember.UserNames[0].Delete(); } } else { // If the user name was not blank then create it ProviderUserName userName; if (aMember.UserNames.Count > 0) { userName = aMember.UserNames[0]; } else { userName = new ProviderUserName(); userName.MemberId = aMember.Id.Value; userName.CreateDate = DateTime.UtcNow; } userName.EditDate = DateTime.UtcNow; userName.UserName = model.UserName; userName.Save(); } return true; }
public static bool Save(RegisterVM model, ref ProviderMember registerMember) { registerMember.Password = model.Password; registerMember.CreateDate = DateTime.UtcNow; registerMember.EditDate = DateTime.UtcNow; registerMember.Save(); if (!string.IsNullOrWhiteSpace(model.Email)) { ProviderEmail anEmail = new ProviderEmail(); anEmail.MemberId = registerMember.Id.Value; anEmail.IsValidated = false; anEmail.CreateDate = DateTime.UtcNow; anEmail.EditDate = DateTime.UtcNow; anEmail.Email = new MailAddress(model.Email); anEmail.Save(); } if(!string.IsNullOrWhiteSpace(model.UserName)) { ProviderUserName aUserName = new ProviderUserName(); aUserName.MemberId = registerMember.Id.Value; aUserName.CreateDate = DateTime.UtcNow; aUserName.EditDate = DateTime.UtcNow; aUserName.UserName = model.UserName; aUserName.Save(); } return true; }
/// <summary> /// Function that fetches the owner of the article /// </summary> /// <param name="info">Info regarding a particular e-mail article</param> /// <returns>The provider member who is the owner of this e-mail article</returns> public static ProviderMember GetEmailOwner(MessageInfo info) { ProviderMember aMember; string email = info.Envelope.Sender[0].Address; MailAddress address = new MailAddress(email); long? memberId = ProviderEmail.FindOwner(address, null); if (memberId.HasValue) { _log.Info("E-mail sender has an account."); aMember = new ProviderMember(memberId.Value); } else { _log.Info("Person does not have an account. Creating one."); aMember = new ProviderMember(); aMember.CreateDate = DateTime.UtcNow; aMember.EditDate = DateTime.UtcNow; aMember.Save(); ProviderEmail memberEmail = new ProviderEmail(); memberEmail.CreateDate = DateTime.UtcNow; memberEmail.EditDate = DateTime.UtcNow; memberEmail.Email = address; memberEmail.IsValidated = true; memberEmail.MemberId = aMember.Id.Value; memberEmail.Save(); } return aMember; }
public virtual JsonResult DomainIdentificationRequest(string domainAddress) { string from = "APILOGINFO - " + HttpContext.Request.UserHostAddress; InsideWordWebLog.Instance.Buffer(from, "DomainIdentificationRequest(" + domainAddress + ")"); ApiMsgVM returnMessage = new ApiMsgVM(1); Uri domainUri = null; if (!IWStringUtility.TryUrlDecode(domainAddress, out domainAddress) || !Uri.TryCreate(domainAddress, UriKind.Absolute, out domainUri)) { returnMessage.StatusCode = (int)ApiMsgVM.StatusEnum.failure; returnMessage.StatusMessage = domainAddress + " is an invalid uri"; } else { ProviderDomain aDomain = new ProviderDomain(); ProviderIssuedKey issuedKey = new ProviderIssuedKey(); ProviderMember aMember = new ProviderMember(); if (aDomain.Load(domainUri.AbsoluteUri)) { aMember.Load(aDomain.MemberId); } else { // Domain doesn't exist already so create it and a member aMember.CreateDate = DateTime.UtcNow; aMember.EditDate = DateTime.UtcNow; aMember.Save(); aDomain.CreateDate = DateTime.UtcNow; aDomain.EditDate = DateTime.UtcNow; aDomain.Domain = domainUri; aDomain.IsValidated = false; aDomain.MemberId = aMember.Id.Value; aDomain.Save(); } issuedKey.LoadOrCreate(aMember.Id.Value, domainUri.AbsoluteUri, true, 1, false); returnMessage.StatusCode = (int)ApiMsgVM.StatusEnum.success; returnMessage.StatusMessage = "Success"; returnMessage.Content = issuedKey.IssuedKey; } InsideWordWebLog.Instance.Buffer(from, "Done DomainIdentificationRequest - " + returnMessage); return Json(returnMessage); }
/// <summary> /// Function to help determine the owner of an article. If sufficient information is /// provided and the owner does not exist in the system then they will be created. /// </summary> /// <param name="model">view model containing the data of the new article</param> /// <param name="currentMember">the current member using the site</param> /// <returns>Returns a ProviderMember who is the owner of the article</returns> public static ProviderMember GetArticleOwner(ArticleEditorVM model, ProviderArticle anArticle, ProviderCurrentMember currentMember) { ProviderMember owningMember; if (anArticle.MemberId.HasValue) { owningMember = new ProviderMember(anArticle.MemberId.Value); } else if (anArticle.IsNew || !string.IsNullOrEmpty(model.ArticleEmail)) { // Have we been provided with an e-mail of the owner? if (!string.IsNullOrEmpty(model.ArticleEmail)) { MailAddress email = new MailAddress(model.ArticleEmail); long? memberId = ProviderEmail.FindOwner(email, true); if (memberId.HasValue) { // The owner already exists in our system so just retrieve them owningMember = new ProviderMember(memberId.Value); } else { // the owner doesn't exists so create them owningMember = new ProviderMember(); owningMember.CreateDate = DateTime.UtcNow; owningMember.EditDate = DateTime.UtcNow; owningMember.Save(); // attach the e-mail to this member ProviderEmail anEmail = new ProviderEmail(); anEmail.MemberId = owningMember.Id.Value; anEmail.IsValidated = false; anEmail.CreateDate = DateTime.UtcNow; anEmail.EditDate = DateTime.UtcNow; anEmail.Email = email; anEmail.Save(); } } else { // no e-mail provided so just use whoever is currently logged on, whether they be anonymous or not owningMember = currentMember; } } else { // this article has no owner so just return a blank member owningMember = new ProviderMember(); } return owningMember; }