Пример #1
0
        public ActionResult Login(string username, string password)
        {
            try
            {
                var customer = new CustomerItem();

                if (customerRepositoryFE.TryGetByUserNameAndPassword(out customer, username, password))
                {
                    if (!customer.IsActive)
                    {
                        return(Json(new
                        {
                            error = true,
                            message = "Tài khoản của bạn đã bị khóa."
                        }, JsonRequestBehavior.AllowGet));
                    }

                    var customerModel = new CustomerLoggedModel()
                    {
                        ID       = customer.ID,
                        FullName = customer.LastName,
                        Email    = customer.Email,
                        Phone    = customer.Phone,
                        UserName = customer.UserName,
                        Address  = customer.Address
                    };

                    Session["_cus"] = customerModel;

                    Response.Cookies.Add(new HttpCookie("_cus")
                    {
                        Value   = Web365Utility.Web365Utility.StringToBase64(JsonConvert.SerializeObject(customerModel)),
                        Expires = DateTime.Now.AddDays(1)
                    });

                    return(Json(new
                    {
                        error = false,
                        message = "Đăng nhập thành công"
                    }, JsonRequestBehavior.AllowGet));
                }

                return(Json(new
                {
                    error = true,
                    message = "Sai tên đăng nhập hoặc mật khẩu, bạn hãy thử lại."
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
            }

            return(Json(new
            {
                error = true,
                message = "Đăng nhập không thành công, bạn hãy thử lại"
            }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult Register(string name, string email, string password)
        {
            try
            {
                var customerId = 0;

                var customer = new tblCustomer()
                {
                    UserName = email,
                    LastName = name,
                    Email    = email,
                    Password = password
                };

                if (customerRepositoryFE.AddCustomer(out customerId, customer))
                {
                    if (customerId == 0)
                    {
                        return(Json(new
                        {
                            error = true,
                            message = "Email của bạn đã tồn tại."
                        }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var customerModel = new CustomerLoggedModel()
                        {
                            ID       = customerId,
                            FullName = customer.LastName,
                            Email    = customer.Email,
                            Phone    = customer.Phone,
                            UserName = customer.UserName,
                            Address  = customer.Address
                        };

                        Session["_cus"] = customerModel;

                        Response.Cookies.Add(new HttpCookie("_cus")
                        {
                            Value   = Web365Utility.Web365Utility.StringToBase64(JsonConvert.SerializeObject(customerModel)),
                            Expires = DateTime.Now.AddDays(1)
                        });

                        Web365Utility.Web365Utility.SendMail(email, ConfigWeb.Domain + ": Đăng ký thành công", "Bạn đã đăng ký thành công tại " + ConfigWeb.Domain);

                        return(Json(new
                        {
                            error = false
                        }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
            }


            return(Json(new
            {
                error = true,
                message = "Đăng ký không thành công bạn hãy thử lại."
            }, JsonRequestBehavior.AllowGet));
        }