예제 #1
0
        /// <summary>
        /// 登录记录
        /// </summary>
        /// <param name="userInfo"></param>
        /// <param name="ip"></param>
        /// <param name="type"></param>
        public void LoginRecord(UserInfoDto userInfo, string ip, LoginType type)
        {
            var result = ip.GetPhysicsAddressInfo().Result;

            if (result?.Status != 0)
            {
                return;
            }

            string addr   = result.AddressResult.FormattedAddress;
            string prov   = result.AddressResult.AddressComponent.Province;
            var    record = new LoginRecord()
            {
                IP            = ip,
                LoginTime     = DateTime.Now,
                LoginType     = type,
                PhysicAddress = addr,
                Province      = prov
            };
            var u = _userInfoService.GetByUsername(userInfo.Username);

            u.LoginRecord.Add(record);
            _userInfoService.SaveChanges();
            var content = new Template(File.ReadAllText(Path.Combine(_hostEnvironment.WebRootPath, "template", "login.html")))
                          .Set("name", u.Username)
                          .Set("time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                          .Set("ip", record.IP)
                          .Set("address", record.PhysicAddress).Render();

            CommonHelper.SendMail(_settingService.Get(s => s.Name.Equals("Title")).Value + "账号登录通知", content, _settingService.Get(s => s.Name.Equals("ReceiveEmail")).Value, "127.0.0.1");
        }
예제 #2
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // only process for main action, not for Child Action
            if (!filterContext.IsChildAction)
            {
                //string ip = GetRemoteIP();
                //check licence when application run online
                //string serverName = GetServerName();
                //if (EngineContext.Current.CheckLicense()) //IsPrivateIP(ip) ||
                //{
                if (string.IsNullOrEmpty(Title))
                {
                    //Set default Title for page
                    string area       = MvcHelpers.GetAreaName(filterContext.RouteData);
                    string controller = MvcHelpers.GetControllerName(filterContext.RouteData);
                    string action     = MvcHelpers.GetActionName(filterContext.RouteData);
                    //Set default Title for page
                    Title = action + " | " + controller;
                    if (area != "" && controller != area)
                    {
                        Title += " | " + area;
                    }
                }

                if (string.IsNullOrEmpty(MetaDescription))
                {
                    MetaDescription = systemSettingService.Get("MetaDescription");
                }

                if (string.IsNullOrEmpty(MetaKeyword))
                {
                    MetaKeyword = systemSettingService.Get("MetaKeyword");
                }
                //}
                //else
                //{
                //    //Show Invalid Licence
                //    filterContext.Result = RedirectToAction("Invalid", new { area = "Users", controller = "Licence" });
                //}
            }

            base.OnActionExecuting(filterContext);
        }
예제 #3
0
        /// <summary>
        /// 登录记录
        /// </summary>
        /// <param name="userInfo"></param>
        /// <param name="ip"></param>
        /// <param name="type"></param>
        public void LoginRecord(UserInfoDto userInfo, string ip, LoginType type)
        {
            var record = new LoginRecord()
            {
                IP            = ip,
                LoginTime     = DateTime.Now,
                LoginType     = type,
                PhysicAddress = ip.GetIPLocation()
            };
            var u = _userInfoService.GetByUsername(userInfo.Username);

            u.LoginRecord.Add(record);
            _userInfoService.SaveChanges();
            var content = new Template(File.ReadAllText(Path.Combine(_hostEnvironment.WebRootPath, "template", "login.html")))
                          .Set("name", u.Username)
                          .Set("time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
                          .Set("ip", record.IP)
                          .Set("address", record.PhysicAddress).Render();

            CommonHelper.SendMail(_settingService.Get(s => s.Name.Equals("Title")).Value + "账号登录通知", content, _settingService.Get(s => s.Name.Equals("ReceiveEmail")).Value, "127.0.0.1");
        }
예제 #4
0
        public ActionResult SendContact(ContactForm model)
        {
            try
            {
                if (!Request.IsAjaxRequest())
                {
                    return(Json(new
                    {
                        title = "Gửi liên hệ",
                        success = false,
                        errors = string.Join(", ", ModelState.Values.SelectMany(v =>
                                                                                from x in v.Errors
                                                                                select x.ErrorMessage).ToArray())
                    }));
                }

                string serverPathEmail = string.Concat(Server.MapPath("\\"), Contains.TemplateMailBasicContact);
                if (System.IO.File.Exists(serverPathEmail))
                {
                    const string messageId = "Email";
                    string       subject   = "Thông tin liên hệ";

                    var body = string.Concat("", "Người gửi: ", model.FullName, "<br>");
                    body = string.Concat(body, string.Concat("E-mail: ", model.Email), "<br>");
                    body = string.Concat(body, model.Content, "<br>");

                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(serverPathEmail);
                    XmlNode xmlNodes = xmlDocument.SelectSingleNode(string.Concat("MailFormats/MailFormat[@Id='", messageId, "']"));

                    string subjectNodes = xmlNodes.SelectSingleNode("Subject")?.InnerText;
                    subjectNodes = subject.Replace(string.Concat(subject, "?"), subject);

                    string bodyNodes = xmlNodes.SelectSingleNode("Body")?.InnerText;
                    bodyNodes = body.Replace(string.Concat(body, "?"), body);

                    var toEmail = _systemSettingService.Get(x => x.Status == 1).Email;

                    var sendMail = new SendMail
                    {
                        MessageId = "Email",
                        ToEmail   = toEmail,
                        Subject   = subjectNodes,
                        Body      = bodyNodes
                    };

                    //_sendMailService.SendMailSmtp(sendMail);

                    model.SuccessfullySent = true;
                    model.Result           = "Gửi liên hệ thành công, chúng tôi sẽ liên lạc với bạn ngay khi có thể.";
                }

                return(Json(new
                {
                    title = "Gửi liên hệ",
                    success = true,
                    message = "Gửi liên hệ thành công, chúng tôi sẽ liên lạc với bạn ngay khi có thể."
                }));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }