public AuthorizationController(
            OpenIddictApplicationManager <Applications> applicationManager,
            IOptions <IdentityOptions> identityOptions,
            SignInManager <Users> signInManager,
            UserManager <Users> userManager,
            IDistributedCache cache,
            ApplicationDbContext dbContext,
            UserLoginLogManager userLoginLogManager,
            IConfigurationRoot config,
            ISystemClock clock)
        {
            _applicationManager = applicationManager;
            _identityOptions    = identityOptions;
            _signInManager      = signInManager;
            _userManager        = userManager;
            _cache = cache;
            _userLoginLogManager = userLoginLogManager;
            _dbContext           = dbContext;
            _config = config;
            string timeStr   = _config["TokenExpiresIn"];
            long   expiresIn = 0;

            long.TryParse(timeStr ?? "", out expiresIn);
            if (expiresIn <= 0)
            {
                expiresIn = 3600;
            }
            tokenExpiresIn = expiresIn;
            _clock         = clock;
            serviceApiUrl  = config["ServiceApi"];
            restClient     = new RestClient(serviceApiUrl);
        }
        public async Task UserLoginAsync(UserLoginMessage message)
        {
            await Task.Delay(5000);

            await UserLoginLogManager.CreateAsync(message.MapTo(new UserLoginLogParameter()));

            await UnitOfWork.CommitAsync();
        }
        //private static bool _databaseChecked;

        public AccountController(
            UserManager <Users> userManager,
            SignInManager <Users> signInManager,
            IEmailSender emailSender,
            ISmsSender smsSender,
            UserLoginLogManager userLoginLogManager,
            ApplicationDbContext applicationDbContext)
        {
            _userManager          = userManager;
            _signInManager        = signInManager;
            _emailSender          = emailSender;
            _smsSender            = smsSender;
            _userLoginLogManager  = userLoginLogManager;
            _applicationDbContext = applicationDbContext;
        }
 public UserLoginLogsController(UserLoginLogManager userLoginLogManager, PermissionExpansionManager permissionExpansionManager)
 {
     _userLoginLogManager        = userLoginLogManager;
     _permissionExpansionManager = permissionExpansionManager;
 }
Ejemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.CacheControl = "no-cache";
            context.Response.AddHeader("Pragma", "no-cache");
            context.Response.ContentType = "text/plain";
            string Action = context.Request["action"];

            switch (Action)
            {
            case "GetDistrict":
                ServiceAreaManager areaManager = new ServiceAreaManager();
                DataTable          dtArea      = areaManager.GetAreaList(int.Parse(context.Request["levelType"]), int.Parse(context.Request["parentId"]));
                context.Response.Write(JsonHelper.DataTableToJson("success", "获取数据成功", dtArea, "ServiceArea"));
                context.Response.End();
                break;

            case "GetServiceAreaByID":
                ServiceAreaManager manager = new ServiceAreaManager();
                DataTable          dt      = manager.GetServiceAreaByID(context.Request["key"]);
                context.Response.Write(JsonHelper.DataTableToJson("success", "获取数据成功", dt, "ServiceArea"));
                context.Response.End();
                break;

            case "UpdateServiceAreaCoordinates":
                ServiceAreaManager sam = new ServiceAreaManager();
                string             key = context.Request["key"];
                Hashtable          ht  = sam.GetInfoByID(key);
                ht["COORDINATES"] = context.Request["Coordinates"];
                ht["LONGITUDE"]   = context.Request["Longitude"];
                ht["LATITUDE"]    = context.Request["Latitude"];
                string areaType   = ht["AREATYPE"].ToString();
                string status     = ht["STATUS"].ToString();
                string deleteMark = ht["DELETEMARK"].ToString();
                //AreaType 区域类型 1服务范围 2停车网点
                //Status 启动状态:0禁用,1启用
                //DeleteMark 0
                if ("1".Equals(areaType) && "1".Equals(status) && "True".Equals(deleteMark))
                {
                    ICache cache = null;
                    try
                    {
                        cache = CacheFactory.GetCache();
                        string   cacheKey = "Service_Area_" + ht["CITYID"].ToString();
                        DateTime timeSpan = DateTime.Now.AddDays(10);
                        cache.Set(cacheKey, context.Request["Coordinates"], timeSpan - DateTime.Now);
                        cache.Dispose();

                        /*List<LatLng> area_pts = new List<LatLng>();
                         * string coordinates = cache.Get<string>(cacheKey);
                         * if(coordinates!=null&& coordinates.Length>0)
                         * foreach (string str in coordinates.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries))
                         * {
                         *  string[] pt_arr = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                         *  LatLng pt = new LatLng(double.Parse(pt_arr[1]), double.Parse(pt_arr[0]));
                         *  area_pts.Add(pt);
                         * }*/
                    }
                    catch (Exception e)
                    {
                        if (cache != null)
                        {
                            cache.Dispose();
                        }
                        Logger.Error("更新区域:" + ht["THISNAME"].ToString() + ",报错:" + e);
                    }
                    if (cache != null)
                    {
                        cache.Dispose();
                    }
                }
                if (sam.AddOrEditInfo(ht, key))
                {
                    context.Response.Write(JsonHelper.DataTableToJson("success", "更新成功", null, "UpdateServiceAreaCoordinates"));
                }
                else
                {
                    context.Response.Write(JsonHelper.DataTableToJson("faild", "更新失败", null, "UpdateServiceAreaCoordinates"));
                }
                context.Response.End();
                break;

            case "GetInviteCouponInfo":
                SysSettingManager settingManager = new SysSettingManager();
                int couponNum = 0;
                int.TryParse(settingManager.GetValueByKey("InviteCouponNum"), out couponNum);
                decimal couponMoney = 0.00m;
                decimal.TryParse(settingManager.GetValueByKey("InviteCouponMoney"), out couponMoney);
                double CouponPeriod = 0;
                double.TryParse(settingManager.GetValueByKey("CouponPeriod"), out CouponPeriod);
                Hashtable result_ht = new Hashtable();
                result_ht["CouponNum"]    = couponNum;
                result_ht["CouponMoney"]  = couponMoney;
                result_ht["CouponPeriod"] = DateTime.Now.Date.AddDays(CouponPeriod).ToString("yyyy-MM-dd");
                //响应数据到客户端
                context.Response.Write(SiteHelper.GetJsonFromHashTable2(result_ht, "success", "获取数据成功", "GetInviteCouponInfo"));
                break;

            case "SendVerificationCode":
                string mobie = context.Request["Mobile"].ToString().Trim();
                string code  = "";
                if (context.Request["Code"] != null)
                {
                    code = context.Request["Code"].ToString().Trim();
                }
                else
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "faild", "参数错误", "SendVerificationCode"));
                    context.Response.End();
                    break;
                }
                string session_code = context.Session["dt_session_code"].ToString();
                if (code.ToLower() != session_code.ToLower())
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "faild", "图形验证码错误", "SendVerificationCode"));
                    context.Response.End();
                    break;
                }
                SmsInfoManager  sim  = new SmsInfoManager();
                UserInfoManager uim  = new UserInfoManager();
                DataTable       user = uim.GetUserInfoByBindPhone(mobie);
                if (user != null && user.Rows.Count > 0)
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "faild", "手机号已注册", "SendVerificationCode"));
                    context.Response.End();
                    break;
                }
                bool sendResult = sim.SendVerificationCode(mobie);
                if (sendResult)
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "success", "发送验证码成功", "SendVerificationCode"));
                    context.Response.End();
                    break;
                }
                else
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "faild", "发送验证码失败", "SendVerificationCode"));
                    context.Response.End();
                    break;
                }

            case "NewUserRegister":
                sim = new SmsInfoManager();
                UserLoginLogManager ullm = new UserLoginLogManager();
                uim            = new UserInfoManager();
                settingManager = new SysSettingManager();
                string mobile           = context.Request["Mobile"].ToString().Trim();
                string verificationCode = context.Request["VerificationCode"].ToString().Trim();
                string invite_userid    = context.Request["InviteUserID"].ToString().Trim();

                string vcode = sim.GetVerCodeByMobile(mobile);
                if (verificationCode != vcode)
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "faild", "手机验证码错误", "NewUserRegister"));
                    context.Response.End();
                    return;
                }

                user = uim.GetUserInfoByBindPhone(mobile);
                if (user != null && user.Rows.Count > 0)
                {
                    context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "faild", "用户已注册", "NewUserRegister"));
                    context.Response.End();
                    return;
                }
                else
                {
                    Hashtable newuser = new Hashtable();
                    newuser["BindPhone"]             = mobile;
                    newuser["RealNameCertification"] = (int)UserRealNameCertification.Unauthorized;
                    newuser["UserState"]             = (int)UserState.Enable;
                    newuser["Balance"]      = 0;
                    newuser["RaiseBalance"] = 0;
                    newuser["IsRaiseUser"]  = (int)UserIsRaise.NO;
                    newuser["InviteCode"]   = mobile;
                    newuser["InviteUserID"] = invite_userid;
                    int num = uim.AddUserInfo(newuser);
                    if (num > -1)
                    {
                        user = uim.GetUserInfoByBindPhone(mobile);

                        //新注册用户赠送优惠券
                        couponNum = 0;
                        int.TryParse(settingManager.GetValueByKey("RegCouponNum"), out couponNum);
                        couponMoney = 0.00m;
                        decimal.TryParse(settingManager.GetValueByKey("RegCouponMoney"), out couponMoney);
                        UserCouponManager couponManager = new UserCouponManager();
                        if (couponNum > 0 && couponMoney > 0)
                        {
                            couponManager.NewUserGiveCoupons(user.Rows[0]["ID"].ToString());
                        }

                        context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "success", "新用户注册成功", "NewUserRegister"));
                        context.Response.End();
                        return;
                    }
                    else
                    {
                        context.Response.Write(SiteHelper.GetJsonFromHashTable2(null, "faild", "手机号错误", "NewUserRegister"));
                        context.Response.End();
                        return;
                    }
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 6
0
        public string Execute(Hashtable params_ht)
        {
            Hashtable res = params_ht;

            if (res["Mobile"] == null ||
                res["VerificationCode"] == null ||
                res["Client"] == null ||
                res["Longitude"] == null ||
                res["Latitude"] == null ||
                res["EquipmentID"] == null ||
                res["Mobile"].ToString().Trim().Length <= 0 ||
                res["VerificationCode"].ToString().Trim().Length <= 0 ||
                res["Client"].ToString().Trim().Length <= 0 ||
                res["Longitude"].ToString().Trim().Length <= 0 ||
                res["Latitude"].ToString().Trim().Length <= 0 ||
                res["EquipmentID"].ToString().Trim().Length <= 0)
            {
                return(SiteHelper.GetJsonFromHashTable(null, "faild", "登录数据不完整"));
            }
            else
            {
                UserInfoManager     uim            = new UserInfoManager();
                SmsInfoManager      sim            = new SmsInfoManager();
                UserLoginLogManager ullm           = new UserLoginLogManager();
                SysSettingManager   settingManager = new SysSettingManager();
                bool isAllowLogin = false;
                //获取参数
                mobile           = res["Mobile"].ToString().Trim();
                verificationCode = res["VerificationCode"].ToString().Trim();
                client           = res["Client"].ToString().Trim();
                longitude        = res["Longitude"].ToString().Trim();
                latitude         = res["Latitude"].ToString().Trim();
                drviceid         = res["EquipmentID"].ToString().Trim();
                DataTable user = uim.GetUserInfoByBindPhone(mobile);
                if (user != null && user.Rows.Count > 0)
                {
                    string vcode = sim.GetVerCodeByMobile(mobile);
                    if (vcode != null && verificationCode.Trim() == vcode.Trim())
                    {
                        isAllowLogin = true;
                    }
                    else
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "验证码不正确"));
                    }
                }
                else
                {
                    Hashtable newuser = new Hashtable();
                    newuser["BindPhone"]             = mobile;
                    newuser["RealNameCertification"] = (int)UserRealNameCertification.Unauthorized;
                    newuser["UserState"]             = (int)UserState.Enable;
                    newuser["Balance"]      = 0;
                    newuser["RaiseBalance"] = 0;
                    newuser["IsRaiseUser"]  = (int)UserIsRaise.NO;
                    newuser["InviteCode"]   = mobile;
                    int num = uim.AddUserInfo(newuser);
                    if (num > -1)
                    {
                        user = uim.GetUserInfoByBindPhone(mobile);
                        string vcode = sim.GetVerCodeByMobile(mobile);
                        if (vcode != null && verificationCode.Trim() == vcode.Trim())
                        {
                            isAllowLogin = true;
                        }
                        else
                        {
                            return(SiteHelper.GetJsonFromHashTable(null, "faild", "验证码不正确"));
                        }
                    }
                    else
                    {
                        return(SiteHelper.GetJsonFromHashTable(null, "faild", "手机号错误"));
                    }

                    //新注册用户赠送优惠券
                    int couponNum = 0;
                    int.TryParse(settingManager.GetValueByKey("RegCouponNum"), out couponNum);
                    decimal couponMoney = 0.00m;
                    decimal.TryParse(settingManager.GetValueByKey("RegCouponMoney"), out couponMoney);
                    UserCouponManager couponManager = new UserCouponManager();
                    if (couponNum > 0 && couponMoney > 0)
                    {
                        couponManager.NewUserGiveCoupons(user.Rows[0]["ID"].ToString());
                    }
                }
                if (isAllowLogin)
                {
                    //记录登录日志
                    Hashtable loginlog = new Hashtable();
                    loginlog["UserID"]    = user.Rows[0]["ID"].ToString();
                    loginlog["Latitude"]  = latitude;
                    loginlog["Longitude"] = longitude;
                    loginlog["Client"]    = client;
                    ullm.AddUserLoginLog(loginlog);
                    //更新最后登录时间
                    Hashtable userh = new Hashtable();
                    userh["LastloginTime"] = SiteHelper.GetWebServerCurrentTime();
                    userh["DeviceID"]      = drviceid;
                    uim.AddOrEditUserInfo(userh, loginlog["UserID"].ToString());

                    decimal balance = 0.00m;
                    decimal.TryParse(user.Rows[0]["Balance"].ToString(), out balance);
                    decimal balance2 = 0.00m;
                    decimal.TryParse(user.Rows[0]["Balance2"].ToString(), out balance2);
                    user.Rows[0]["Balance"] = balance + balance2;
                    if (user.Rows[0]["UserType"].ToString() == UserType.OffDepositUser.GetHashCode().ToString())//免押金用户
                    {
                        string depositMoney = settingManager.GetValueByKey("GoldDepositAmount");
                        user.Rows[0]["Deposit"] = depositMoney;
                    }

                    //响应数据到客户端
                    return(SiteHelper.GetJsonFromHashTable(DataTableHelper.DataRowToHashTable(user.Rows[0]), "success", "登录成功", "UserInfo"));
                }
                else
                {
                    return(SiteHelper.GetJsonFromHashTable(null, "faild", "登录操作失败"));
                }
            }
        }