Exemplo n.º 1
0
        public ActionResult Reset(string username)
        {
            ResetModel mm = new ResetModel();

            try
            {
                IuserService _userService    = IoC.Resolve <IuserService>();
                Company      _currentCompany = ((EInvoiceContext)FXContext.Current).CurrentCompany;
                user         model           = _userService.Query.Where(u => u.GroupName.Equals(_currentCompany.id.ToString()) && u.username == username).FirstOrDefault();
                if (model != null)
                {
                    string randompass = IdentityManagement.WebProviders.RBACMembershipProvider.CreateRandomPassword(8);
                    IService.IRegisterEmailService emailSrv      = FX.Core.IoC.Resolve <IService.IRegisterEmailService>();
                    Dictionary <string, string>    subjectParams = new Dictionary <string, string>(1);
                    subjectParams.Add("$subject", "");
                    Dictionary <string, string> bodyParams = new Dictionary <string, string>(3);
                    bodyParams.Add("$password", randompass);
                    bodyParams.Add("$site", FX.Utils.UrlUtil.GetSiteUrl());
                    emailSrv.ProcessEmail("*****@*****.**", model.email, "ResetPassword", subjectParams, bodyParams);
                    model.password = GeneratorPassword.EncodePassword(randompass, model.PasswordFormat, model.PasswordSalt);//FormsAuthentication.HashPasswordForStoringInConfigFile(randompass, "MD5");
                    model.LastPasswordChangedDate = DateTime.Now;
                    _userService.Save(model);
                    _userService.CommitChanges();
                    mm.lblErrorMessage = "Kiểm tra email để lấy mật khẩu của bạn.";
                    return(View("ResetPassword", mm));
                }
                mm.lblErrorMessage = "Tài khoản không tồn tại trên hệ thống";
                return(View("ResetPassword", mm));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ResetModel model = new ResetModel();
                model.lblErrorMessage = "Tài khoản không tồn tại trên hệ thống";
                return(View("ResetPassword", mm));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(Customer tmp, CustomerModel model, string[] DeliverMethod)
        {
            if (string.IsNullOrWhiteSpace(tmp.Name) || string.IsNullOrWhiteSpace(tmp.Code))
            {
                Messages.AddErrorMessage("Cần nhập các thông tin bắt buộc.");
                model.tmpCustomer = tmp;
                return(View(model));
            }
            IRBACMembershipProvider _MemberShipProvider = FX.Core.IoC.Resolve <IRBACMembershipProvider>();
            // kiểm tra tài khoản được sử dụng chưa
            user us = _MemberShipProvider.GetUser(tmp.AccountName, true);

            if (us != null)
            {
                Messages.AddErrorMessage("Tài khoản có trong hệ thống.");
                model.tmpCustomer = tmp;
                return(View(model));
            }
            Company          _currentCom  = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            ICustomerService cusSrv       = IoC.Resolve <ICustomerService>();
            string           ErrorMessage = "";
            var qr = cusSrv.Query.Where(p => p.ComID == _currentCom.id);

            if (!string.IsNullOrWhiteSpace(tmp.TaxCode))
            {
                qr = qr.Where(p => p.TaxCode.ToUpper() == tmp.TaxCode.ToUpper() || p.Code.ToUpper() == tmp.Code.Trim().ToUpper());
            }
            else
            {
                qr = qr.Where(p => p.Code.ToUpper() == tmp.Code.Trim().ToUpper());
            }
            if (qr.Count() > 0)
            {
                model.tmpCustomer = tmp;
                Messages.AddErrorMessage("Mã số thuế hoặc mã khách hàng đã tồn tại trên hệ thống!");
                return(View(model));
            }
            Certificate cer = model.UpdateCertificate(new Certificate());

            // user user = new user();
            //add delivermethod
            if (DeliverMethod == null)
            {
                tmp.DeliverMethod = -1;
            }
            else if (DeliverMethod.Length == 1)
            {
                if (DeliverMethod[0] == "0")
                {
                    tmp.DeliverMethod = 0;
                }
                else if (DeliverMethod[0] == "1")
                {
                    tmp.DeliverMethod = 1;
                }
            }
            else if (DeliverMethod.Length == 2)
            {
                tmp.DeliverMethod = 2;
            }

            tmp.TaxCode = Utils.formatTaxcode(tmp.TaxCode);
            //end delivermethod
            if (cusSrv.CreateCus(tmp, cer, _currentCom.id, out ErrorMessage))
            {
                log.Info("Create Customer by: " + HttpContext.User.Identity.Name + " Info-- TenKhachHang: " + tmp.Name + " TaiKhoanKhachHang: " + tmp.AccountName + " Email: " + tmp.Email);
                Messages.AddFlashMessage(Resources.Message.Cus_IMesSuccess);
                // send Mail--
                try
                {
                    if (!string.IsNullOrEmpty(tmp.Email))
                    {
                        string randompass = (_currentCom.Config.Keys.Contains("SetDefaultCusPass")) ? _currentCom.Config["SetDefaultCusPass"] : "******";
                        string labelEmail = _currentCom.Config.Keys.Contains("LabelMail") ? _currentCom.Config["LabelMail"] : "*****@*****.**";
                        string portalLink = _currentCom.Config.Keys.Contains("PortalLink") ? _currentCom.Config["PortalLink"] : "http://hddt.vinvoice.vn";
                        IService.IRegisterEmailService emailSrv      = FX.Core.IoC.Resolve <IService.IRegisterEmailService>();
                        Dictionary <string, string>    subjectParams = new Dictionary <string, string>(1);
                        subjectParams.Add("$subject", "");
                        Dictionary <string, string> bodyParams = new Dictionary <string, string>(3);
                        bodyParams.Add("$company", _currentCom.Name);
                        bodyParams.Add("$cusname", tmp.Name);
                        bodyParams.Add("$username", tmp.AccountName);
                        bodyParams.Add("$password", randompass);
                        bodyParams.Add("$portalLink", portalLink);
                        emailSrv.ProcessEmail(labelEmail, tmp.Email, "RegisterCustomer", subjectParams, bodyParams);
                    }
                }
                catch (Exception ex)
                { log.Error(ex); }
                return(RedirectToAction("Index"));
            }
            else
            {
                model.tmpCustomer = tmp;
                Messages.AddErrorMessage(ErrorMessage);
                log.Error(" Create  -:" + ErrorMessage);
                return(View(model));
            }
        }