public JsonResult ResendConfirmationCode(string email) { var client = db.Clients.FirstOrDefault(c => c.Email == email); if (client == null) { return(Json(new { error = "No such email registered with us!" })); } if (client.IsConfirmed) { return(Json(new { error = "You already confirmed your account." })); } BackAgain: var confirmationToken = RandomNumbers.GenerateCoupen(); if (db.Clients.Any(c => c.ConfirmationToken == confirmationToken)) { goto BackAgain; } client = db.Clients.FirstOrDefault(c => c.Token == client.Token); if (client == null) { return(Json(false)); } try { client.ConfirmationToken = confirmationToken; db.SubmitChanges(); client.ClientResentConfirmationCode(db); client.SendEmail(db.Site()); return(Json(true)); } catch { return(Json(new { error = "Currently we're unable to send you a confirmation code via email. We apologize for this inconvenience.\n\n" + "Our admin is being alerted about this situation. He'll contact you soon.\n\n" + "Please check your email 10 minutes later.", isEmailError = true })); } }
public ActionResult _ChangePassword() { var client = db.Clients.FirstOrDefault(c => c.Token == LoginHelper.Client.Token); if (client == null) { return(Redirect("/logout")); } if (client.ForgotPasswordToken.IsEmpty()) { client.ForgotPasswordToken = RandomNumbers.GenerateCoupen(); db.SubmitChanges(); } return(Redirect("/confirm-password.html#" + client.ForgotPasswordToken)); }
public JsonResult ForgotPassword(string email) { var user = db.Clients.FirstOrDefault(a => a.Email == email); if (user == null) { return(Json("No such email has been registered in our site.<br /><br />Please make sure that you entered a valid email address?<br /><br />You can directly contact us via our <a href=\"/contact-us.html\">Contact</a> section.")); } try { user.ForgotPasswordToken = RandomNumbers.GenerateCoupen(); db.SubmitChanges(); user.SendChangePasswordEmail(db.Site()); return(Json(true)); } catch { return(Json(false)); } }
public JsonResult New() { var form = Request.Form; string name = form["name"], password = form["password"], email = form["email"], address = form["address"], postalCode = form["postalCode"], state = form["state"], city = form["city"], country = form["country"], cellPhone = form["cellPhone"], subscribe = form["subscribe"]; if (db.Clients.Any(a => a.Email == email)) { return(Json(new { error = "This email address is being used by someone else. Please pick a unique email address." })); } GoBack: var token = RandomNumbers.GetRandomNumbers(); if (db.Clients.Any(c => c.Token == token)) { goto GoBack; } BackAgain: var confirmationToken = RandomNumbers.GenerateCoupen(); if (db.Clients.Any(c => c.ConfirmationToken == confirmationToken)) { goto BackAgain; } var client = new Client { Name = name, Password = BCrypt.HashPassword(password, BCrypt.GenerateSalt(8)), Email = email.ToLower(), Address = address, PostalCode = postalCode, State = state, MobilePhone = cellPhone, HomePhone = "", Token = token, City = city, Country = country, SubscribeNewsletter = subscribe == "1", IsConfirmed = false, ConfirmationToken = confirmationToken, RegistrationDate = UKTime.Now }; try { db.Clients.InsertOnSubmit(client); db.SubmitChanges(); client.SendEmail(db.Site()); return(Json(new { name = client.Name, cell = client.MobilePhone, email = client.Email, landline = client.HomePhone })); } catch { return(Json(new { error = "Currently we're unable to send you a confirmation code via email. We apologize for this inconvenience.\n\n" + "Our admin is being alerted about this situation. He'll contact you soon.\n\n" + "Please check your email 10 minutes later.", isEmailError = true })); } }
public JsonResult ConfirmBooking() { var form = Request.Form; string customerName = form["customerName"], cellNumber = form["cellNumber"], pickFrom = form["pickFrom"], dropTo = form["dropTo"], vehicleType = form["vehicleType"], email = form["email"], payAs = form["payAs"], additionalInfo = form["additionalInfo"], fare = form["fare"], landLine = form["landLine"], handLag = form["handLag"], journeyType = form["journeyType"], stops = form["stops"], returnTimeString = form["returnTime"], passengerName = form["passengerName"], passengerCell = form["passengerCell"], bonusToken = form["bonusToken"]; var clientToken = "None"; if (LoginHelper.Client != null) { var client = LoginHelper.Client; clientToken = client.Token; } int numberOfPassengers; int.TryParse(form["numberOfPassengers"], out numberOfPassengers); int childSeats; int.TryParse(form["childSeats"], out childSeats); int babySeats; int.TryParse(form["babySeats"], out babySeats); int luggage; int.TryParse(form["luggage"], out luggage); int handLagNumber; int.TryParse(handLag, out handLagNumber); DateTime pickupTime; DateTime.TryParse(form["pickupTime"], out pickupTime); DateTime returnTime = UKTime.Now; if (!returnTimeString.IsEmpty()) { DateTime.TryParse(returnTimeString, out returnTime); } GoBack: var token = RandomNumbers.GetRandomNumbers(); if (_db.Jobs.Any(j => j.Token == token)) { goto GoBack; } BackAgain: var confirmationToken = RandomNumbers.GenerateCoupen(); if (_db.Jobs.Any(j => j.ConfirmationToken == confirmationToken)) { goto BackAgain; } const int bottleOfWater = 2; string newspaper = null; var vehicle = vehicleType.GetVehicle(_db); if (vehicle.Name == "Executive") { newspaper = form["newspaper"]; } string drink = null; if (vehicle.Name == "Gold-Vip") { drink = form["drink"]; newspaper = form["newspaper"]; } int jobNumber = 1; if (_db.Jobs.Any()) { jobNumber = (_db.Jobs.OrderByDescending(j => j.JobNumber).FirstOrDefault() ?? new Job { JobNumber = 0 }).JobNumber + 1; } var site = _db.Site(); var job = new Job { Name = customerName, PickFrom = pickFrom, DropTo = dropTo, PickupTime = pickupTime, Fare = fare, NumberOfPassengers = numberOfPassengers, Luggage = luggage, ClientToken = clientToken, PaidAs = payAs, Token = token, VehicleToken = vehicleType, ChildSeats = childSeats, BabySeats = babySeats, CellNumber = cellNumber, Stops = stops, DriverToken = "None", Status = "Active", Email = email, AdditionalInfo = additionalInfo, LandLine = landLine, HandLag = handLagNumber, JourneyType = journeyType, ReturnTime = returnTime, IsConfirmed = false, ConfirmationToken = confirmationToken, BottleOfWater = bottleOfWater, Newspaper = newspaper, Drink = drink, JobNumber = jobNumber, SiteToken = site.Token, BookingFrom = site.Token, BookingTime = UKTime.Now, MinicabOffice = "", BusinessAccountHolder = "", CardTransactionCode = "" }; if (!passengerName.IsEmpty()) { job.PassengerName = passengerName; job.PassengerCell = passengerCell; } try { _db.Jobs.InsertOnSubmit(job); _db.SubmitChanges(); string message; if (!bonusToken.IsEmpty()) { var discount = _db.Discounts.FirstOrDefault( d => d.Token == bonusToken && d.ClientToken == LoginHelper.Client.Token && !d.IsExpired && d.ValidTill >= UKTime.Now); if (discount != null) { discount.JobToken = job.Token; discount.IsExpired = true; _db.SubmitChanges(); } else { message = "Invalid bonus token ( " + bonusToken + " ) used for this job!"; _db.NotifyOperator(JobType.NewJob, message, job.Token); } } message = "New job added by " + job.Name + " ( Cell: " + job.CellNumber + " | Email: " + job.Email + " )"; _db.NotifyOperator(JobType.NewJob, message, job.Token); if (job.Fare.IsEmpty() || job.Fare == "0" || job.Fare == "NaN") { message = "Unable to count fare for job added by " + job.Name + " ( Cell: " + job.CellNumber + " | Email: " + job.Email + " )"; _db.NotifyOperator(JobType.JobError, message, job.Token); _db.SendEmailToAdmin("Unable to Count Fare for a booking!", message); } } catch (Exception ex) { string errorMessage = "Unable to add booking for: " + job.Name + " ( Cell: " + job.CellNumber + " | Email: " + job.Email + " )"; errorMessage += "<br />"; errorMessage += "<br />Pick from: " + job.PickFrom; errorMessage += "<br />Drop to: " + job.DropTo; if (!job.Stops.IsEmpty()) { job.Stops = stops.Replace(",", "=====").Replace("-----", ","); var splittedStops = stops.Split(','); int index = 0; foreach (var stop in splittedStops) { index++; errorMessage += "<br />" + index + ". " + stop; } } errorMessage += "<br />Pickup time: " + job.PickupTime; errorMessage += "<br />Journey type: " + job.JourneyType; errorMessage += "<br />Vehicle: " + job.VehicleToken; errorMessage += "<br />Fare: " + job.Fare; errorMessage += "<br /><br />Error Message:<br /><br /> " + ex; _db.NotifyOperator(JobType.JobError, errorMessage); _db.SendEmailToAdmin("Unable to add booking", errorMessage); const string message = "We are really sorry to say that something went wrong on our servers.<br />However, an automatic message has been sent to the administrator.<br />We will contact you soon via email or call."; if (LoginHelper.Client != null) { LoginHelper.Client.NotifyClient(_db, "Something went wrong", message); } return(Json(message)); } //------------------------------------------------------------------------------------- //-------------------- Now sending email confirmation message //------------------------------------------------------------------------------------- try { //job.SendEmail(_db.Site(), airportCharges); //job.JobSentConfirmationCode(_db); return(Json( new { booked = true, registered = LoginHelper.Client != null, token = LoginHelper.Client != null ? job.ConfirmationToken : null })); } catch { string errorMessage = "Unable to send confirmation email to: " + job.Name + " ( Cell: " + job.CellNumber + " | Email: " + job.Email + " )"; _db.NotifyOperator(JobType.JobError, errorMessage, job.Token); _db.SendEmailToAdmin("New Booking: Unable to send confirmation code!", errorMessage); var message = "We are unable to drop a confirmation code at your email: <a href=\"mailto:" + job.Email + "\">" + job.Email + "</a><br />An automatic email has been sent to the administrator.<br />We will send you confirmation code in a few minutes at your email address: <a href=\"mailto:" + job.Email + "\">" + job.Email + "</a>"; if (LoginHelper.Client != null) { LoginHelper.Client.NotifyClient(_db, "Unable to send confirmation code", message, job.Token); } return(Json(message)); } }