Пример #1
0
        public ApiResult <ForgetPasswordViewModel> ForgetPassword(ForgetPasswordViewModel model)
        {
            var    dbResult     = new ApiResult <ForgetPasswordViewModel>();
            string errorMessage = string.Empty;

            try
            {
                // Kiểm tra dữ liệu
                var ValidPassword = ValidateForgetPassword(model);
                if (!ValidPassword.Succeeded)
                {
                    return(ValidPassword);
                }

                // Tạo token code và thời gian hết hạn
                string   tokenCode = EncryptCore.Md5Get(DateTime.Now.Ticks + model.Email + EncryptCore.KeyEncrypt);;
                DateTime tokenExp  = DateTime.Now.AddDays(1);

                // Lấy kết quả trả về từ DB
                dbResult = userDAL.ForgetPassword(model, tokenCode, tokenExp);

                // Kiểm tra kết quả
                if (dbResult.Succeeded)
                {
                    // Tạo nội dung của email
                    var otpEmailFormat =
                        new
                    {
                        HoTen = dbResult.Data.FirstName,
                        Link  = model.UrlForm + "?Token=" + tokenCode
                    };
                    var msgEmailOtp = EmailContentHtml.EmailContentFormat(otpEmailFormat, "ResetPassword.html");

                    // Gửi email cho user
                    var emailSendStt = EmailUtility.SendMail(ConfigUtil.Email_DisplayName, model.Email, "Quên mật khẩu", msgEmailOtp);
                }

                return(dbResult);
            }
            catch (Exception ex)
            {
                dbResult.Failed(new ErrorObject()
                {
                    Code        = Constants.ERR_EXCEPTION,
                    Description = ex.Message
                });
                return(dbResult);
            }
        }
Пример #2
0
        public IHttpActionResult Abort(AbortModel Item)
        {
            ApiResult <bool> rs = orderDAL.Abort(Item.Id, UserInfo.Id);

            if (!rs.Succeeded)
            {
                return(Content(HttpStatusCode.BadRequest, rs));
            }
            OrderDetail Order     = orderDAL.GetOne(Item.Id).Data;
            object      EmailData = new
            {
                Order.RoomName,
                Reason = Item.ReasonAbort
            };

            string EmailContent = EmailContentHtml.EmailContentFormat(EmailData, "Abort.html");
            bool   e            = EmailUtility.SendMail(ConfigUtil.Email_DisplayName, Order.GuestEmail, "Thông báo hủy đơn đặt phòng.", messages: EmailContent);

            return(Ok(rs));
        }
Пример #3
0
        public IHttpActionResult Register(UserPostData item)
        {
            var Rs = new ApiResult <User>();

            if (!ModelState.IsValid)
            {
                // Lỗi validate dữ liệu trả ra từ model
                foreach (string key in ModelState.Keys)
                {
                    ModelState current = ModelState[key];
                    foreach (ModelError error in current.Errors)
                    {
                        Rs.Failed(new ErrorObject()
                        {
                            Code        = key,
                            Description = error.ErrorMessage
                        });
                    }
                }
                return(Content(HttpStatusCode.BadRequest, Rs));
            }

            if (item.RoleId == 0)
            {
                item.RoleId = 1;
            }
            UserResult userInfo;

            try
            {
                userInfo = UserInfo;
            }
            catch (Exception)
            {
                userInfo = new UserResult();
            }

            if (userInfo.Id > 0)
            {
                item.CreatedUser = userInfo.Id;
            }
            item.Password = Libs.GetMd5(item.Password + EncryptCore.PassKey);
            Rs            = userDAL.Register(item);
            if (Rs.Succeeded)
            {
                string OTP = userDAL.GetOtp(Rs.Data.Id);
                string Url = ConfigUtil.DomainBaseHttp + "/Api/Acc/ConfirmEmail?Id=" + Rs.Data.Id.ToString() + "&OTP=" + OTP;
                if (!String.IsNullOrEmpty(item.SucRedirectUrl))
                {
                    Url += "&SucRedirectUrl=" + item.SucRedirectUrl;
                }

                if (!String.IsNullOrEmpty(item.FailRedirectUrl))
                {
                    Url += "&FailRedirectUrl=" + item.FailRedirectUrl;
                }
                object DataContent = new
                {
                    Link = Url,
                    item.FirstName
                };
                var EmailContent = EmailContentHtml.EmailContentFormat(DataContent, "ConfirmEmail.html");
                var e            = EmailUtility.SendMail(ConfigUtil.Email_DisplayName, item.Email, "Xác thực Email", EmailContent);
                return(Ok(Rs));
            }
            else
            {
                return(Content(HttpStatusCode.BadRequest, Rs));
            }
        }
Пример #4
0
        public IHttpActionResult ResendOTP(UserResendEmail user)
        {
            var Rs = new ApiResult <User>();

            if (user.Id == 0)
            {
                Rs.Failed(new ErrorObject
                {
                    Code        = "User Id",
                    Description = "User Id is required"
                });
                return(Content(HttpStatusCode.BadRequest, Rs));
            }

            if (!ModelState.IsValid)
            {
                IEnumerable <string> message = ModelState.Values.SelectMany(v => v.Errors)
                                               .Select(e => e.ErrorMessage);
                foreach (var i in message)
                {
                    Rs.Failed(new ErrorObject
                    {
                        Code        = "Validate_Exception",
                        Description = i.ToString()
                    });
                }
                return(Content(HttpStatusCode.BadRequest, Rs));
            }
            var UserInf = userDAL.GetById(user.Id);

            if (UserInf.Data != null && UserInf.Data.Id > 0)
            {
                var item = UserInf.Data;
                if (item.EmailConfirmed > 0)
                {
                    Rs.Failed(new ErrorObject
                    {
                        Code        = "ERR",
                        Description = "Email is confirmed"
                    });
                    return(Ok(Rs));
                }
                string OTP = userDAL.GetOtp(item.Id);
                string Url = ConfigUtil.DomainBaseHttp + "/Api/Acc/ConfirmEmail?Id=" + item.Id.ToString() + "&OTP=" + OTP;

                if (!String.IsNullOrEmpty(user.SucRedirectUrl))
                {
                    Url += "&SucRedirectUrl=" + user.SucRedirectUrl;
                }

                if (!String.IsNullOrEmpty(user.FailRedirectUrl))
                {
                    Url += "&FailRedirectUrl=" + user.FailRedirectUrl;
                }
                object DataContent = new
                {
                    Link = Url,
                    item.FirstName
                };
                var EmailContent = EmailContentHtml.EmailContentFormat(DataContent, "ConfirmEmail.html");
                if (EmailContent == null || EmailContent == "")
                {
                    return(BadRequest());
                }
                var e = EmailUtility.SendMail(ConfigUtil.Email_DisplayName, item.Email, "Xác thực Email", EmailContent);
            }
            else
            {
                Rs.Failed(new ErrorObject
                {
                    Code        = "NOT_FOUND",
                    Description = "User not found"
                });
                return(Content(HttpStatusCode.NotFound, Rs));
            }
            return(Ok(Rs));
        }
Пример #5
0
        public IHttpActionResult Insert(PostOrder Item)
        {
            string tokenCode = HttpContext.Current.Request.Headers["TokenCode"] != null ? HttpContext.Current.Request.Headers["TokenCode"].ToString() : "";

            Models.UserResult UserInfo = null;

            if (!string.IsNullOrEmpty(tokenCode))
            {
                UserInfo = CacheUtil.GetCacheObject(tokenCode);
            }
            int UserId = (UserInfo != null && UserInfo.Id > 0) ? UserInfo.Id : 0;

            ApiResult <NewOrderResult> rs = new ApiResult <NewOrderResult>()
            {
                Data = new NewOrderResult()
            };

            if (Item == null || Item.Order == null)
            {
                rs.Failed(new ErrorObject
                {
                    Code        = "EXCEPTION",
                    Description = "Đéo nhận Data truyền vào."
                });
                return(Content(HttpStatusCode.BadRequest, rs));
            }

            if (!ModelState.IsValid)
            {
                // Lỗi validate dữ liệu trả ra từ model
                foreach (string key in ModelState.Keys)
                {
                    ModelState current = ModelState[key];
                    foreach (ModelError error in current.Errors)
                    {
                        rs.Failed(new ErrorObject()
                        {
                            Code        = key,
                            Description = error.ErrorMessage
                        });
                    }
                }

                return(Content(HttpStatusCode.BadRequest, rs));
            }

            Item.Order.TokenCode = RandomString(15);
            rs = orderDAL.Insert(Item.Order, UserId);

            if (!rs.Succeeded)
            {
                return(Content(HttpStatusCode.BadRequest, rs));
            }

            string Link = ConfigUtil.DomainBaseHttp + "/API/Order/Confirm?Id="
                          + rs.Data.Id.ToString()
                          + "&TokenCode=" + Item.Order.TokenCode
                          + "&SucUrl=" + Item.SucUrl
                          + "&FailUrl=" + Item.FailUrl;

            object EmailData = new
            {
                Link,
                Item.Order.GuestName,
                SetTime = DateTime.Now.ToString(),
                Item.Order.RoomName
            };

            string EmailContent = EmailContentHtml.EmailContentFormat(EmailData, "ConfirmOrder.html");
            bool   e            = EmailUtility.SendMail(ConfigUtil.Email_DisplayName, Item.Order.GuestEmail, "Xác thực Đơn đặt phòng", messages: EmailContent);

            return(Ok(rs));
        }