Ejemplo n.º 1
0
        public JsonResult Login(string email, string password)
        {
            if (_db.Clients.Any(c => c.Email == email))
            {
                var client = _db.Clients.FirstOrDefault(c => c.Email == email);
                if (client == null)
                {
                    return(Json(false));
                }

                if (!client.IsConfirmed)
                {
                    return(Json(new { error = "Please confirm your account. We have sent you a confirmation token at: <a href=\"mailto:" + client.Email + "\">" + client.Email + "</a><br /<br />Want to resend confirmation token? <a href=\"/resend-confirmation-token.html\"> Click here </a>." }));
                }

                if (BCrypt.CheckPassword(password, client.Password))
                {
                    client.Token.AddCookie();
                    _db.ValidateCookie();

                    return(Json(true));
                }
            }

            return(Json(false));
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            db.ValidateCookie();
            if (LoginHelper.Client != null)
            {
                return(Redirect("/Client/"));
            }

            return(View());
        }
Ejemplo n.º 3
0
 public ClientController()
 {
     db.ValidateCookie();
 }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
 public MainController()
 {
     _db.ValidateCookie();
 }