public override string ResetPassword(string userName, string answer) { string newPassword = Membership.GeneratePassword(6, 0); string passwordAnswer = String.Empty; GetAttributesRequest request = new GetAttributesRequest() .WithDomainName(Settings.Default.AWSMembershipDomain) .WithItemName(userName) .WithAttributeName(PasswordStrings); GetAttributesResult result = this._simpleDBClient.GetAttributes(request).GetAttributesResult; if (result != null) { foreach (Attribute att in result.Attribute) { switch (att.Name) { case "PasswordAnswer": { passwordAnswer = att.Value; break; } } } } else { throw new MembershipPasswordException("User not found"); } if (this.RequiresQuestionAndAnswer && !this.CheckPassword(answer, passwordAnswer)) { throw new MembershipPasswordException("Incorrect password answer."); } ReplaceableAttribute replace = new ReplaceableAttribute() .WithName(PasswordStrings[0]) .WithValue(newPassword) .WithReplace(true); PutAttributesRequest prequest = new PutAttributesRequest() .WithDomainName(Settings.Default.AWSMembershipDomain) .WithItemName(userName) .WithAttribute(replace); this._simpleDBClient.PutAttributes(prequest); return newPassword; }
public static void Main(string[] args) { AmazonSimpleDB sdb = AWSClientFactory.CreateAmazonSimpleDBClient(RegionEndpoint.USWest2); try { Console.WriteLine("==========================================="); Console.WriteLine("Getting Started with Amazon SimpleDB"); Console.WriteLine("===========================================\n"); // Creating a domain Console.WriteLine("Creating domain called MyStore.\n"); String domainName = "MyStore"; CreateDomainRequest createDomain = (new CreateDomainRequest()).WithDomainName(domainName); sdb.CreateDomain(createDomain); // Listing domains ListDomainsResponse sdbListDomainsResponse = sdb.ListDomains(new ListDomainsRequest()); if (sdbListDomainsResponse.IsSetListDomainsResult()) { ListDomainsResult listDomainsResult = sdbListDomainsResponse.ListDomainsResult; Console.WriteLine("List of domains:\n"); foreach (String domain in listDomainsResult.DomainName) { Console.WriteLine(" " + domain); } } Console.WriteLine(); // Putting data into a domain Console.WriteLine("Putting data into MyStore domain.\n"); String itemNameOne = "Item_01"; PutAttributesRequest putAttributesActionOne = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameOne); List<ReplaceableAttribute> attributesOne = putAttributesActionOne.Attribute; attributesOne.Add(new ReplaceableAttribute().WithName("Category").WithValue("Clothes")); attributesOne.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Sweater")); attributesOne.Add(new ReplaceableAttribute().WithName("Name").WithValue("Cathair Sweater")); attributesOne.Add(new ReplaceableAttribute().WithName("Color").WithValue("Siamese")); attributesOne.Add(new ReplaceableAttribute().WithName("Size").WithValue("Small")); attributesOne.Add(new ReplaceableAttribute().WithName("Size").WithValue("Medium")); attributesOne.Add(new ReplaceableAttribute().WithName("Size").WithValue("Large")); sdb.PutAttributes(putAttributesActionOne); String itemNameTwo = "Item_02"; PutAttributesRequest putAttributesActionTwo = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameTwo); List<ReplaceableAttribute> attributesTwo = putAttributesActionTwo.Attribute; attributesTwo.Add(new ReplaceableAttribute().WithName("Category").WithValue("Clothes")); attributesTwo.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Pants")); attributesTwo.Add(new ReplaceableAttribute().WithName("Name").WithValue("Designer Jeans")); attributesTwo.Add(new ReplaceableAttribute().WithName("Color").WithValue("Paisley Acid Wash")); attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("30x32")); attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("32x32")); attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("32x34")); sdb.PutAttributes(putAttributesActionTwo); String itemNameThree = "Item_03"; PutAttributesRequest putAttributesActionThree = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameThree); List<ReplaceableAttribute> attributesThree = putAttributesActionThree.Attribute; attributesThree.Add(new ReplaceableAttribute().WithName("Category").WithValue("Clothes")); attributesThree.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Pants")); attributesThree.Add(new ReplaceableAttribute().WithName("Name").WithValue("Sweatpants")); attributesThree.Add(new ReplaceableAttribute().WithName("Color").WithValue("Blue")); attributesThree.Add(new ReplaceableAttribute().WithName("Color").WithValue("Yellow")); attributesThree.Add(new ReplaceableAttribute().WithName("Color").WithValue("Pink")); attributesThree.Add(new ReplaceableAttribute().WithName("Size").WithValue("Large")); attributesThree.Add(new ReplaceableAttribute().WithName("Year").WithValue("2006")); attributesThree.Add(new ReplaceableAttribute().WithName("Year").WithValue("2007")); sdb.PutAttributes(putAttributesActionThree); String itemNameFour = "Item_04"; PutAttributesRequest putAttributesActionFour = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameFour); List<ReplaceableAttribute> attributesFour = putAttributesActionFour.Attribute; attributesFour.Add(new ReplaceableAttribute().WithName("Category").WithValue("Car Parts")); attributesFour.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Engine")); attributesFour.Add(new ReplaceableAttribute().WithName("Name").WithValue("Turbos")); attributesFour.Add(new ReplaceableAttribute().WithName("Make").WithValue("Audi")); attributesFour.Add(new ReplaceableAttribute().WithName("Model").WithValue("S4")); attributesFour.Add(new ReplaceableAttribute().WithName("Year").WithValue("2000")); attributesFour.Add(new ReplaceableAttribute().WithName("Year").WithValue("2001")); attributesFour.Add(new ReplaceableAttribute().WithName("Year").WithValue("2002")); sdb.PutAttributes(putAttributesActionFour); String itemNameFive = "Item_05"; PutAttributesRequest putAttributesActionFive = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameFive); List<ReplaceableAttribute> attributesFive = putAttributesActionFive.Attribute; attributesFive.Add(new ReplaceableAttribute().WithName("Category").WithValue("Car Parts")); attributesFive.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Emissions")); attributesFive.Add(new ReplaceableAttribute().WithName("Name").WithValue("O2 Sensor")); attributesFive.Add(new ReplaceableAttribute().WithName("Make").WithValue("Audi")); attributesFive.Add(new ReplaceableAttribute().WithName("Model").WithValue("S4")); attributesFive.Add(new ReplaceableAttribute().WithName("Year").WithValue("2000")); attributesFive.Add(new ReplaceableAttribute().WithName("Year").WithValue("2001")); attributesFive.Add(new ReplaceableAttribute().WithName("Year").WithValue("2002")); sdb.PutAttributes(putAttributesActionFive); // Getting data from a domain Console.WriteLine("Print attributes with the attribute Category that contain the value Clothes.\n"); String selectExpression = "Select * From MyStore Where Category = 'Clothes'"; SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression); SelectResponse selectResponse = sdb.Select(selectRequestAction); if (selectResponse.IsSetSelectResult()) { SelectResult selectResult = selectResponse.SelectResult; foreach (Item item in selectResult.Item) { Console.WriteLine(" Item"); if (item.IsSetName()) { Console.WriteLine(" Name: {0}", item.Name); } foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attribute) { Console.WriteLine(" Attribute"); if (attribute.IsSetName()) { Console.WriteLine(" Name: {0}", attribute.Name); } if (attribute.IsSetValue()) { Console.WriteLine(" Value: {0}", attribute.Value); } } } } Console.WriteLine(); // Deleting values from an attribute Console.WriteLine("Deleting Blue attributes in Item_O3.\n"); Amazon.SimpleDB.Model.Attribute deleteValueAttribute = new Amazon.SimpleDB.Model.Attribute().WithName("Color").WithValue("Blue"); DeleteAttributesRequest deleteValueAction = new DeleteAttributesRequest().WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(deleteValueAttribute); sdb.DeleteAttributes(deleteValueAction); //Deleting an attribute Console.WriteLine("Deleting attribute Year in Item_O3.\n"); Amazon.SimpleDB.Model.Attribute deleteAttribute = new Amazon.SimpleDB.Model.Attribute().WithName("Year"); DeleteAttributesRequest deleteAttributeAction = new DeleteAttributesRequest().WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(deleteAttribute); sdb.DeleteAttributes(deleteAttributeAction); //Replacing an attribute Console.WriteLine("Replace Size of Item_03 with Medium.\n"); ReplaceableAttribute replaceableAttribute = new ReplaceableAttribute().WithName("Size").WithValue("Medium").WithReplace(true); PutAttributesRequest replaceAction = new PutAttributesRequest().WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(replaceableAttribute); sdb.PutAttributes(replaceAction); //Deleting an item Console.WriteLine("Deleting Item_03 item.\n"); DeleteAttributesRequest deleteItemAction = new DeleteAttributesRequest().WithDomainName("MyStore").WithItemName("Item_03"); sdb.DeleteAttributes(deleteAttributeAction); //Deleting a domain Console.WriteLine("Deleting MyStore domain.\n"); DeleteDomainRequest deleteDomainAction = new DeleteDomainRequest().WithDomainName("MyStore"); sdb.DeleteDomain(deleteDomainAction); } catch (AmazonSimpleDBException ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); Console.WriteLine("XML: " + ex.XML); } Console.WriteLine("Press Enter to continue..."); Console.Read(); }
/// <summary> /// Puts attribiutes in SimpleDB /// </summary> /// <param name="domainName"></param> /// <param name="itemName"></param> /// <param name="name"></param> /// <param name="replace"></param> /// <param name="value"></param> public void PutAttribute(string domainName, string itemName, string name, bool replace, string value) { var replaceableAttribute = new ReplaceableAttribute { Name = name, Replace = replace, Value = value }; var request = new PutAttributesRequest { DomainName = domainName, ItemName = itemName, Attribute = new List<ReplaceableAttribute>() { replaceableAttribute } }; Client.PutAttributes(request); }
public override string ResetPassword(string username, string answer) { if (!EnablePasswordReset) { throw new NotSupportedException("Password reset is not enabled."); } if (answer == null && RequiresQuestionAndAnswer) { throw new ProviderException("Password answer required for password reset."); } string newPassword = System.Web.Security.Membership.GeneratePassword(6, 0); string passwordAnswer = ""; try { GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttributeName(new string[] { "Password", "PasswordAnswer" }); GetAttributesResponse response = client.GetAttributes(request); if (response.IsSetGetAttributesResult()) { GetAttributesResult result = response.GetAttributesResult; foreach (Attribute att in result.Attribute) { switch (att.Name) { case "PasswordAnswer": passwordAnswer = att.Value; break; default: break; } } } else throw new MembershipPasswordException("User not found"); if (RequiresQuestionAndAnswer && !CheckPassword(answer, passwordAnswer)) { throw new MembershipPasswordException("Incorrect password answer."); } // Update the new password here ReplaceableAttribute replace = new ReplaceableAttribute().WithName("Password").WithValue(newPassword).WithReplace(true); PutAttributesRequest prequest = new PutAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttribute(replace); client.PutAttributes(prequest); } catch (Exception e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "ResetPassword"); throw new ProviderException(exceptionMessage); } else { throw e; } } return newPassword; }
public override bool ChangePassword(string username, string oldPwd, string newPwd) { if (!ValidateUser(username, oldPwd)) return false; try { ReplaceableAttribute replaceAttribute = new ReplaceableAttribute().WithName("Password").WithValue(newPwd).WithReplace(true); PutAttributesRequest request = new PutAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttribute(replaceAttribute); client.PutAttributes(request); return true; } catch (Exception e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "ChangePassword"); throw new ProviderException(exceptionMessage); } else { throw e; } } return false; }
public static void AmazonBatchPutPost(List<ForumPost> awsPosts,int threadIndex) { SimpleDB.Client.OnSimpleDBResponse += BatchPutAttributeWebResponse; BatchPutAttributesRequest request = new BatchPutAttributesRequest() { DomainName = "coreDB" }; ReplaceableAttribute attributesOne = new ReplaceableAttribute().WithName("votes").WithValue("0").WithReplace(true); ReplaceableAttribute attributesTwo = new ReplaceableAttribute().WithName("module").WithValue(data.modules[data.curModuleIndex].CourseCode.ToString()); ReplaceableAttribute attributesThree = new ReplaceableAttribute().WithName("AWSTimestamp").WithValue(data.modules[data.curModuleIndex].lastUpdated.ToString()).WithReplace(true); ReplaceableAttribute attributesFour; ReplaceableAttribute attributesFive = new ReplaceableAttribute().WithName("root").WithValue(data.modules[data.curModuleIndex].jPosts["Results"][0]["Threads"][threadIndex]["ID"].ToString()); //int forumIndex = 0; //int i = 0; List<ReplaceableItem> replacableItem = request.Items; int t = 0; //List<ForumPostTitle> titles = fetchForumTitles(data.curModuleIndex, data.curForumIndex, 0); foreach (var post in awsPosts) { attributesFour = new ReplaceableAttribute().WithName("title").WithValue(post.Heading.ToString()); //attributesFive = new ReplaceableAttribute().WithName("subscriber").WithValue(data.modules[data.curModuleIndex].lastUpdated.ToString()); ReplaceableItem repItem = new ReplaceableItem() { ItemName = post.ID.ToString() }; repItem.Attribute.Add(attributesOne); repItem.Attribute.Add(attributesTwo); repItem.Attribute.Add(attributesThree); repItem.Attribute.Add(attributesFour); repItem.Attribute.Add(attributesFive); replacableItem.Add(repItem); t++; } SimpleDB.Client.BatchPutAttributes(request); }