public ActionResult Register(UserModel user) { if (ModelState.IsValid) { using (var ctx = new StoresEntities()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(user.Password); var sysUser = ctx.Users.Create(); sysUser.Email = user.Email; sysUser.Password = encrpPass; sysUser.PasswordSalt = crypto.Salt; sysUser.UserId = Guid.NewGuid(); ctx.Users.Add(sysUser); sysUser.Roles.Add(ctx.Roles.FirstOrDefault(r => r.Name.Equals("member"))); ctx.SaveChanges(); return(RedirectToAction("Index", "User")); } } ViewBag.Title = "Email is already in use!"; return(View(user)); }
public override string[] GetRolesForUser(string email) { using (var ctx = new StoresEntities()) { var objUser = ctx.Users.FirstOrDefault(x => x.Email == email); if (objUser == null) { return(null); } else { string[] ret = objUser.Roles.Select(x => x.Name).ToArray(); return(ret); } } }
public ActionResult ChangePassword() { var loggedUser = User.Identity.Name; using (var ctx = new StoresEntities()) { var user = ctx.Users.FirstOrDefault(u => u.Email.Equals(loggedUser)); if (user == null) { return(HttpNotFound()); } return(View(new UserModel { Password = user.Password, Email = user.Email })); } }
private bool IsValid(string email, string password) { var crypto = new SimpleCrypto.PBKDF2(); bool isValid = false; using (var ctx = new StoresEntities()) { var user = ctx.Users.FirstOrDefault(u => u.Email.Equals(email)); if (user != null) { if (user.Password.Equals(crypto.Compute(password, user.PasswordSalt))) { isValid = true; } } } return(isValid); }
public ActionResult ChangePassword(string OldPassword, string NewPassword, string ConfirmNewPassword) { if (IsValid(User.Identity.Name.ToString(), OldPassword)) { if (NewPassword.Equals(ConfirmNewPassword)) { using (var ctx = new StoresEntities()) { var crypto = new SimpleCrypto.PBKDF2(); var encrpPass = crypto.Compute(NewPassword); var sysUser = ctx.Users.FirstOrDefault(s => s.Email.Equals(User.Identity.Name.ToString())); sysUser.PasswordSalt = crypto.Salt; sysUser.Password = encrpPass; ctx.SaveChanges(); return(RedirectToAction("Index", "Member")); } } else { ViewBag.Title = "New password does not match the confirmed one!"; } } else { ViewBag.Title = "Original password does not match!"; } using (var ctx = new StoresEntities()) { var user = ctx.Users.FirstOrDefault(s => s.Email.Equals(User.Identity.Name.ToString())); return(View(new UserModel { Password = user.Password, Email = user.Email })); } }
private static void Upload() { Console.Write("Creating Working Copy..."); // wait on the long-running create operation and get back the new working copy dataset's id var datasetId = CreateWorkingCopy(); Console.WriteLine(" {0}", datasetId); Console.WriteLine("Truncating Working Copy..."); var truncate = TruncateWorkingCopy(datasetId); var batchSize = 1000; using (var db = new StoresEntities()) { LinkedList <Dictionary <string, object> > rows = new LinkedList <Dictionary <string, object> >(); var mostRecent = db.Stores.Select(s => s.LastSeen).Max(s => (DateTime?)s); var mostRecentStores = db.Stores.Where(s => s.LastSeen == mostRecent); Console.WriteLine("Got {0} stores to upload for {1} batch", mostRecentStores.Count(), mostRecent.ToString()); var numUpserted = 0; foreach (var store in mostRecentStores) { List <string> streetPieces = new List <string>(); string streetCombined; if (store.Street1 != null && store.Street1.Trim() != "") { streetPieces.Add(store.Street1.Trim()); } if (store.Street2 != null && store.Street2.Trim() != "") { streetPieces.Add(store.Street2.Trim()); } if (store.Street3 != null && store.Street3.Trim() != "") { streetPieces.Add(store.Street3.Trim()); } streetCombined = String.Join(", ", streetPieces); var row = new Dictionary <string, object>(); row.Add("Store ID", store.StarbucksStoreID); row.Add("Name", store.Name); row.Add("Brand", store.BrandName); row.Add("Store Number", store.StoreNumber); row.Add("Phone Number", store.PhoneNumber); row.Add("Ownership Type", store.OwnershipType); row.Add("Street Combined", streetCombined); row.Add("Street 1", store.Street1); row.Add("Street 2", store.Street2); row.Add("Street 3", store.Street3); row.Add("City", store.City); row.Add("Country Subdivision", store.CountrySubdivisionCode); row.Add("Country", store.CountryCode); row.Add("Postal Code", store.PostalCode); row.Add("Latitude", store.Latitude); row.Add("Longitude", store.Longitude); row.Add("Timezone", store.TZID); row.Add("Current Timezone Offset", store.TZOffset); row.Add("Olson Timezone", store.TZOlsonID); row.Add("First Seen", store.FirstSeen.ToUniversalTime()); // if we add the coordinates when we don't have them, the rows don't error, but magically disappear... f*****g socrata if (store.Latitude != null && store.Longitude != null) { row.Add("Coordinates", String.Format("({0}, {1})", store.Latitude, store.Longitude)); } /* * row = new Dictionary<string, object>(); * row.Add("ID", new System.Random().Next()); * row.Add("Name", "Foo"); */ rows.AddLast(row); //Console.WriteLine("Added store {0}", store.StarbucksStoreID); if (rows.Count >= batchSize) { DateTime startTime = DateTime.UtcNow; Console.Write("Upserting batch of {0}", rows.Count); var result = Upsert(datasetId, rows); numUpserted += rows.Count; Console.WriteLine(" {0} rows / second. {1} left.", Math.Round((rows.Count / (DateTime.UtcNow - startTime).TotalSeconds), 3), (mostRecentStores.Count() - numUpserted)); rows.Clear(); } } if (rows.Count > 0) { Console.WriteLine("Upserting last batch of {0}", rows.Count); var result = Upsert(datasetId, rows); rows.Clear(); } } Console.WriteLine("Publishing working copy {0}", datasetId); PublishDataSet(datasetId); }
static void Main(string[] args) { Console.WriteLine("Are you SURE you created a working copy and updated the dataset ID in your app.config?"); var key = Console.ReadKey(); if (key.Key != ConsoleKey.Y) { Console.WriteLine("Exiting..."); Environment.Exit(1); } using (var db = new StoresEntities()) { string host = ConfigurationManager.AppSettings["SocrataHost"]; string datasetId = ConfigurationManager.AppSettings["SocrataDatasetID"]; string username = ConfigurationManager.AppSettings["SocrataUsername"]; string password = ConfigurationManager.AppSettings["SocrataPassword"]; string appToken = ConfigurationManager.AppSettings["SocrataAppToken"]; var basicAuthClient = new Soda2Client(username, password, appToken); var dataset = basicAuthClient.getDatasetInfo <Row>(host, datasetId); // truncate the new working copy we created - it's easier just to dump all new results and not horribly time consuming Console.WriteLine("Truncating"); dataset.truncate(); LinkedList <Row> rows = new LinkedList <Row>(); // get the most recent LastSeen date, so we know what our new batch is var mostRecent = db.Stores.Select(s => s.LastSeen).Max(s => (DateTime?)s); // get all the stores in the most recent batch var mostRecentStores = db.Stores.Where(s => s.LastSeen == mostRecent); Row row; foreach (var store in mostRecentStores) { var streetCombined = ""; if (store.Street1 != null && store.Street1.Trim() != "") { streetCombined = streetCombined + store.Street1.Trim(); } if (store.Street2 != null && store.Street2.Trim() != "") { streetCombined = streetCombined + ", " + store.Street2.Trim(); } if (store.Street3 != null && store.Street3.Trim() != "") { streetCombined = streetCombined + ", " + store.Street3.Trim(); } row = new Row(); row.Add("Store ID", store.StarbucksStoreID); row.Add("Name", store.Name); row.Add("Brand", store.BrandName); row.Add("Store Number", store.StoreNumber); row.Add("Phone Number", store.PhoneNumber); row.Add("Ownership Type", store.OwnershipType); row.Add("Street Combined", streetCombined); row.Add("Street 1", store.Street1); row.Add("Street 2", store.Street2); row.Add("Street 3", store.Street3); row.Add("City", store.City); row.Add("Country Subdivision", store.CountrySubdivisionCode); row.Add("Country", store.CountryCode); row.Add("Postal Code", store.PostalCode); row.Add("Latitude", store.Latitude); row.Add("Longitude", store.Longitude); row.Add("Timezone", store.TZID); row.Add("Current Timezone Offset", store.TZOffset); row.Add("Olson Timezone", store.TZOlsonID); rows.AddLast(row); Console.WriteLine("Added store " + store.StarbucksStoreID); if (rows.Count > 2000) { Console.WriteLine("Upserting batch"); dataset.upsert(rows.ToArray()); rows.Clear(); } } if (rows.Count > 0) { Console.WriteLine("Upserting last"); dataset.upsert(rows.ToArray()); } Console.WriteLine("Complete"); Console.ReadKey(); } }
public BaseRepository() { Context = new StoresEntities(); }