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

            if (result?.Status == 0)
            {
                string      addr   = result.AddressResult.FormattedAddress;
                string      prov   = result.AddressResult.AddressComponent.Province;
                LoginRecord record = new LoginRecord()
                {
                    IP            = ip,
                    LoginTime     = DateTime.Now,
                    LoginType     = type,
                    PhysicAddress = addr,
                    Province      = prov
                };
                UserInfo u = _userInfoService.GetByUsername(userInfo.Username);
                u.LoginRecord.Add(record);
                _userInfoService.UpdateEntitySaved(u);
                string content = File.ReadAllText(Path.Combine(_hostingEnvironment.WebRootPath, "template", "login.html")).Replace("{{name}}", u.Username).Replace("{{time}}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).Replace("{{ip}}", record.IP).Replace("{{address}}", record.PhysicAddress);
                CommonHelper.SendMail(_settingService.GetFirstEntity(s => s.Name.Equals("Title")).Value + "账号登录通知", content, _settingService.GetFirstEntity(s => s.Name.Equals("ReceiveEmail")).Value);
            }
        }