Exemple #1
0
        public ActionResult Confirm(string confirmationToken, string password)
        {
            var client = db.Clients.FirstOrDefault(c => c.ConfirmationToken == confirmationToken);

            if (client == null || BCrypt.CheckPassword(password, client.Password) == false)
            {
                return(Json(false));
            }

            client.IsConfirmed      = true;
            client.RegistrationDate = UKTime.Now; // confirmation date!

            db.SubmitChanges();

            client.ClientConfirmationNotification(db);

            // ---- adding cookies

            client.Token.AddCookie();
            db.ValidateCookie();

            db.SendEmailToAdmin("Confirmed Account", client.Name + " ( " + client.Email + " ) confirmed his account.");

            var discountToken = db.GetDiscountToken("5");

            return(Json(new
            {
                name = client.Name,
                cell = client.MobilePhone,
                email = client.Email,
                landline = client.HomePhone,
                discount = discountToken
            }));
        }
        public JsonResult Confirm(string token, string type, string password, bool isEmail = false)
        {
            var db = new CabDataContext();

            switch (type)
            {
            case "job":
            {
                var booking = db.Jobs.FirstOrDefault(j => j.ConfirmationToken == token);

                if (booking == null || booking.IsConfirmed)
                {
                    db.NotifyOperator("Unknown Error", "A customer tried to confirm booking that not exists or deleted. Booking token provided is: " + token);
                    return(Json("No such booking found!"));
                }

                if (isEmail && booking.Email != password)
                {
                    return(Json("Invalid email or you've not one who booked the job!"));
                }

                if (!isEmail)
                {
                    var client = LoginHelper.Client;
                    if (client == null || BCrypt.CheckPassword(password, client.Password) == false)
                    {
                        return(Json("Invalid password."));
                    }
                }

                booking.IsConfirmed = true;
                db.SubmitChanges();

                booking.JobConfirmationNotification(db);
                db.SendEmailToAdmin("Booking Confirmed", "Booking confirmed by " + booking.Name + " ( " + booking.Email + " ).");

                var site    = db.Site();
                var subject = booking.Name + ": Your booking confirmed successfully!";
                var body    = "Dear " + booking.Name + "!<br /><br />You booking number #" + booking.JobNumber + " confirmed successfully.";
                new Live(site.BookingEmail, site).SendEmail(subject, body, booking.Email);

                var notifications = db.Notifications.Where(n => n.Receiver == booking.ClientToken && n.Type == JobType.SentCodeForJob);
                foreach (var notification in notifications)
                {
                    notification.Status = "Read";
                    db.SubmitChanges();
                }

                return(Json(true));
            }

            case "change-password":
            {
                var client = db.Clients.FirstOrDefault(c => c.ForgotPasswordToken == token);
                if (client == null)
                {
                    return(Json(false));
                }

                client.Password            = BCrypt.HashPassword(password, BCrypt.GenerateSalt(8));
                client.ForgotPasswordToken = null;

                db.SubmitChanges();

                return(Json(true));
            }

            case "account":
            {
                var client = db.Clients.FirstOrDefault(c => c.ConfirmationToken == token);
                if (client == null || BCrypt.CheckPassword(password, client.Password) == false)
                {
                    return(Json(false));
                }

                client.IsConfirmed      = true;
                client.RegistrationDate = UKTime.Now;

                db.SubmitChanges();

                client.ClientConfirmationNotification(db);

                client.Token.AddCookie();
                db.ValidateCookie();

                db.SendEmailToAdmin("Confirmed Account", client.Name + " ( " + client.Email + " ) confirmed his account.");

                db.GetDiscountToken("5");

                return(Json(true));
            }
            }

            return(Json(false));
        }