Exemplo n.º 1
0
        public async Task SaveSession(string email)
        {
            var sessionId   = Guid.NewGuid();
            var userSession = new UserSessionEntity {
                Key = email, LoginDateTime = DateTime.UtcNow, SessionId = sessionId
            };
            await _repositorySession.Add(userSession);

            var userSessionHistory = new UserSessionHistoryEntity {
                Key = email, LoginDateTime = userSession.LoginDateTime, SessionId = sessionId
            };
            await _repositorySessionHistory.Add(userSessionHistory);

            var options = new CookieOptions
            {
                HttpOnly    = true,
                SameSite    = SameSiteMode.Strict,
                Secure      = true,
                Expires     = DateTime.Now.AddHours(1),
                IsEssential = true
            };

            _httpContextAccessor.HttpContext?.Response.Cookies.Append(SessionCookieName, sessionId.ToString(), options);
            TempSession[email] = sessionId.ToString();
        }
Exemplo n.º 2
0
 public UserSessionEntity TryLogin(string loginname, string pwd, out string msg)
 {
     try
     {
         UserSessionEntity info = new UserSessionEntity();
         SqlParameter[]    prms =
         {
             new SqlParameter("@LoginName", loginname)
         };
         msg = string.Empty;
         string    sql = "select UserID, PassWord,AreaID,Telphone,ThirdWxUserName,ThirdWbUserName,ThirdQqUserNameW,NickName,ThirdPictureUrl,p.PicturePath,p.Domain from M_User m left join M_V_Picture p on m.PictureID=p.PictureID where LoginName=@LoginName ";
         DataTable dt  = SQlHelper.ExecuteDataset(SQlHelper.MyConnectStr, CommandType.Text, sql, prms).Tables[0];
         if (dt.Rows.Count > 0)
         {
             if (dt.Rows.Count == 1)
             {
                 if (dt.Rows[0]["PassWord"].ToString() == pwd)
                 {
                     msg = "登录成功";
                     msg = dt.Rows[0]["UserID"].ToString();
                     int userid = int.Parse(dt.Rows[0]["UserID"].ToString());
                     int areaid = dt.Rows[0]["AreaID"].ToString() == "" ? 0 : int.Parse(dt.Rows[0]["AreaID"].ToString());
                     info.Telphone         = dt.Rows[0]["Telphone"].ToString();
                     info.ThirdWxUserName  = dt.Rows[0]["ThirdWxUserName"].ToString();
                     info.ThirdWbUserName  = dt.Rows[0]["ThirdWbUserName"].ToString();
                     info.ThirdQqUserNameW = dt.Rows[0]["ThirdQqUserNameW"].ToString();
                     info.NickName         = dt.Rows[0]["NickName"].ToString();
                     info.ThirdPictureUrl  = dt.Rows[0]["ThirdPictureUrl"].ToString();
                     info.PicturePath      = dt.Rows[0]["PicturePath"].ToString();
                     info.Domain           = dt.Rows[0]["Domain"].ToString();
                     info.UserID           = userid;
                     info.ZoneID           = areaid;
                     return(info);
                 }
                 else
                 {
                     msg = "用户名或密码错误!";
                     return(null);
                 }
             }
             else
             {
                 msg = "您的账户异常(RepeatEvent)";
                 return(null);
             }
         }
         else
         {
             msg = "用户名或者密码错误!";
             return(null);
         }
     }
     catch (Exception ex)
     {
         msg = ex.Message;
         LogUtil.WriteLog(ex);
         return(null);
     }
 }
Exemplo n.º 3
0
    public Task CreateUserSessionAsync(UserSession session, CancellationToken cancellationToken)
    {
        var item = new UserSessionEntity()
        {
            ApplicationName = _applicationDiscriminator
        };

        session.CopyTo(item);
        _sessionDbContext.UserSessions.Add(item);
        return(_sessionDbContext.SaveChangesAsync(cancellationToken));
    }
Exemplo n.º 4
0
        public static string AddSessionIdentity(UserSessionEntity user)
        {
            SessionIdentity si = new SessionIdentity();

            si.CreatedTime = DateTime.Now;
            si.SessionID   = Guid.NewGuid().ToString("N");
            si.UserID      = user.UserID;
            si.ZoneID      = user.ZoneID;
            if (_SessionPools.TryAdd(si.SessionID, si))
            {
                return(si.SessionID);
            }
            else
            {
                return(string.Empty);
            }
        }
Exemplo n.º 5
0
        private async Task SaveUserSession(IWritableDatabase db, User user, string sessionKey, string ipAddress, string extraInfo)
        {
            db.UserSessionLogs.Add(new UserSessionLog
            {
                UserId       = user.Id,
                SessionKey   = sessionKey,
                IpAddress    = ipAddress,
                PlatformType = PlatformType.Web
            });

            // try to adapt with old structure when the game lobby do authentication
            var entitySession = new UserSessionEntity
            {
                UserId     = user.Id,
                SessionKey = sessionKey,
                ExtraInfo  = extraInfo
            };

            db.InsertOrUpdate(entitySession, user.Id);
            await db.SaveChangesAsync();

            var userSession = new UserSession
            {
                IsFunPlay  = false,
                SessionKey = sessionKey,
                UserId     = user.Id,
                User       = user,
                ExtraInfo  = extraInfo
            };
            await cache.SetAsync(userSession.SessionKey, userSession, new DistributedCacheEntryOptions
            {
                SlidingExpiration = TimeSpan.FromMinutes(20)
            });

            // The reason why we cache user id here, because RSlotServer project they store user session
            // on database, and try to get user id by session key from database.
            // for the workaround, we cache user id on the cache, so RSlotServer can get it from cache also.
            await cache.SetAsync(userSession.SessionKey + "_UserId", user.Id, new DistributedCacheEntryOptions
            {
                SlidingExpiration = TimeSpan.FromMinutes(20)
            });
        }
Exemplo n.º 6
0
        public static bool Login(string username, string password)
        {
            bool result = false;
            var  user   = new UserEntity {
                Username = username, Password = password
            };
            var session = new UserSessionEntity {
                Username = username, SessionId = HttpContext.Current.Session.SessionID, IpAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString()
            };

            var response = WebApiHelper.SscCoreRequest("User/Login", new TheSscRequest(user, session)
            {
                AccessKey = Guid.NewGuid().ToString()
            });

            if (response.IsNotNull())
            {
                if (response.ResponseCode.Equals(TheSscResultCode.LoginSucceed))
                {
                    result = true;
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public CommonModule()
            : base("/Common")
        {
            BCtrl_Common commonobj = new BCtrl_Common();

            //获取服务器时间
            Get["FetchServerTime"] = _ =>
            {
                return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                {
                    Status = 1, Tag = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                }));
            };

            Post["/BindPhone"] = _ =>
            {
                try
                {
                    dynamic data  = FetchFormData();
                    string  phone = data.Phone;
                    string  vcode = data.VCode;
                    string  pwd   = data.Pwd;
                    string  msg   = string.Empty;
                    if (CurrentUser != null && SmsMananger.BindPhone(phone, vcode, CurrentUser.UserID, pwd, out msg))
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 1, Msg = "绑定成功!!"
                        }));
                    }
                    else
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 0, Msg = string.IsNullOrEmpty(msg) ? "当前用户无效" : msg
                        }));
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.WriteLog(ex);
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = ex.Message
                    }));
                }
            };

            Post["AddFeedback"] = _ =>
            {
                try
                {
                    FeedbackEntity e = FetchFormData <FeedbackEntity>();
                    e.UserID = CurrentUser.UserID;
                    bool state = commonobj.AddFeedback(e);
                    if (state)
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 1, Msg = "保存成功"
                        }));
                    }
                    else
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 0, Msg = "保存失败"
                        }));
                    }
                }
                catch (Exception ex)
                {
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = ex.Message
                    }));
                }
            };


            Post["/BindSns"] = _ =>
            {
                try
                {
                    dynamic           data     = FetchFormData();
                    string            thirdid  = data.ThirdID;       //Request.Form.ThirdID;
                    string            username = data.ThirdUserName; //Request.Form.ThirdUserName;
                    int               type     = data.ThirdType;     //Request.Form.ThirdType;
                    string            picurl   = data.Url;
                    BCtrl_Auth        authobj  = new BCtrl_Auth();
                    UserSessionEntity ue       = authobj.IsThereExistUser(username, thirdid, type, picurl);
                    if (ue != null)
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 0, Msg = username + " 已是APP用户,无需再次绑定!"
                        }));
                    }

                    bool rt = new BCtrl_Auth().AddSnsBinding(CurrentUser.UserID, username, thirdid, type, picurl);
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = rt ? 1 : 0, Msg = rt ? "绑定成功!" : "绑定失败!请稍后重试"
                    }));
                }
                catch (Exception ex)
                {
                    LogUtil.WriteLog(ex);
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = "服务器连接失败,请稍后重试"
                    }));
                }


                //UserSessionEntity ue = authobj.TryLoginX(username, thirdid, type, picurl);
                //if (ue != null)
                //{
                //    string sessionid = SessionCenter.AddSessionIdentity(ue);
                //    if (!string.IsNullOrEmpty(sessionid))
                //    {
                //        ue.SessionID = sessionid;
                //        return JsonObj<JsonMessageBase<UserSessionEntity>>.ToJson(new JsonMessageBase<UserSessionEntity>() { Status = 1, Msg = "登录成功", Value = ue });
                //    }
                //    else
                //    {
                //        return JsonObj<JsonMessageBase<UserSessionEntity>>.ToJson(new JsonMessageBase<UserSessionEntity>() { Status = 0, Msg = "创建登录会话失败,请稍后重试!" });
                //    }
                //}
                //else
                //{
                //    return JsonObj<JsonMessageBase<UserSessionEntity>>.ToJson(new JsonMessageBase<UserSessionEntity>() { Status = 0, Msg = "登录失败" });
                //}
            };

            #region  根据版本号,获取到时候可以打开内容
            Get["/CheckState"] = _ =>
            {
                try
                {
                    dynamic      data      = FetchFormData();
                    string       verCode   = data.VerCode; //Request.Form.ThirdID;
                    BCtrl_Common commonBll = new BCtrl_Common();
                    bool         isCheck   = commonBll.IsVersionCheck(verCode);
                    return(JsonObj <JsonMessageBase <bool> > .ToJson(new JsonMessageBase <bool>() { Status = 1, Msg = "数据传输完成!!", Value = isCheck }));
                }
                catch (Exception ex)
                {
                    LogUtil.WriteLog(ex);
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = "服务器连接失败,请稍后重试"
                    }));
                }
            };
            #endregion
        }
Exemplo n.º 8
0
        public AuthModule()
            : base("Auth")
        {
            Get["/GetLog/{date}"] = _ => {
                try
                {
                    int d        = _.date;
                    var response = new Response();
                    response.Headers.Add("Content-Disposition", "attachment; filename=log.txt");
                    response.ContentType = "application/octet-stream";
                    string dir = Path.Combine(AppPath.LogFolder, d.ToString());
                    if (Directory.Exists(dir))
                    {
                        string[] files = Directory.GetFiles(dir, "*.txt");
                        if (files.Length > 0)
                        {
                            byte[] buffer = File.ReadAllBytes(files[0]);
                            response.Contents = stream =>
                            {
                                using (BinaryWriter bw = new BinaryWriter(stream))
                                {
                                    bw.Write(buffer);
                                }
                            };
                            return(response);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                catch {
                    return(null);
                }
            };

            Post["/Login"] = _ =>
            {
                dynamic data      = FetchFormData();
                string  loginname = data.LoginName;
                string  pwd       = data.Pwd;
                string  msg       = string.Empty;


                bool state = authobj.CheckUserExist(loginname);
                if (!state)
                {
                    return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 0, Msg = "你所登录的账号不存在!" }));
                }
                UserSessionEntity ue = authobj.TryLogin(loginname, pwd, out msg);
                if (ue != null)
                {
                    string sessionid = SessionCenter.AddSessionIdentity(ue);
                    if (!string.IsNullOrEmpty(sessionid))
                    {
                        ue.SessionID = sessionid;
                        return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 1, Msg = "登录成功", Value = ue }));
                    }
                    else
                    {
                        return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 0, Msg = "创建登录会话失败,请稍后重试!" }));
                    }
                }
                else
                {
                    return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 0, Msg = msg }));
                }
            };

            Post["/LoginX"] = _ =>
            {
                dynamic           data     = FetchFormData();
                string            thirdid  = data.ThirdID;       //Request.Form.ThirdID;
                string            username = data.ThirdUserName; //Request.Form.ThirdUserName;
                int               type     = data.ThirdType;     //Request.Form.ThirdType;
                string            picurl   = data.Url;
                UserSessionEntity ue       = authobj.TryLoginX(username, thirdid, type, picurl);
                if (ue != null)
                {
                    string sessionid = SessionCenter.AddSessionIdentity(ue);
                    if (!string.IsNullOrEmpty(sessionid))
                    {
                        ue.SessionID = sessionid;
                        return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 1, Msg = "登录成功", Value = ue }));
                    }
                    else
                    {
                        return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 0, Msg = "创建登录会话失败,请稍后重试!" }));
                    }
                }
                else
                {
                    return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 0, Msg = "登录失败" }));
                }
            };

            Post["/Register"] = _ =>
            {
                try
                {
                    dynamic data     = FetchFormData();
                    string  phone    = data.Phone;
                    string  code     = data.VCode;
                    string  pwd      = data.Pwd;
                    string  msg      = string.Empty;
                    string  nickName = string.Empty;
                    int     userid   = authobj.RegesiterNewUser(phone, pwd, code, out msg, out nickName);
                    if (userid > 0)
                    {
                        UserSessionEntity ue = new UserSessionEntity();
                        ue.UserID      = userid;
                        ue.ZoneID      = 0;
                        ue.PicturePath = AppUtil.UserDefaultHeader + AppUtil.ConvertJpg;
                        string sessionid = SessionCenter.AddSessionIdentity(ue);
                        if (!string.IsNullOrEmpty(sessionid))
                        {
                            ue.SessionID = sessionid;
                            ue.NickName  = nickName;
                            return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 1, Msg = "注册成功", Value = ue }));
                        }
                        else
                        {
                            return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 0, Msg = "创建登录会话失败,请稍后重试!" }));
                        }
                    }
                    else
                    {
                        return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 0, Msg = msg }));
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.WriteLog(ex);
                    return(JsonObj <JsonMessageBase <UserSessionEntity> > .ToJson(new JsonMessageBase <UserSessionEntity>() { Status = 0, Msg = "注册失败" }));
                }
            };

            Post["/CheckUserExist"] = _ => {
                try
                {
                    dynamic data      = FetchFormData();
                    string  loginname = data.LoginName;
                    bool    state     = authobj.CheckUserExist(loginname);
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 1, Msg = "检测成功", Tag = state.ToString()
                    }));
                }
                catch (Exception ex)
                {
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = ex.Message
                    }));
                }
            };

            Post["/SendVCode"] = _ =>
            {
                try
                {
                    dynamic data  = FetchFormData();
                    string  phone = data.Phone;
                    string  msg   = string.Empty;
                    if (SmsMananger.SendCode(phone, out msg))
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 1, Msg = msg
                        }));
                    }
                    else
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 0, Msg = msg
                        }));
                    }
                }
                catch (Exception ex)
                {
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = ex.Message
                    }));
                }
            };

            Post["/ResetMyPassword"] = _ => {
                try
                {
                    dynamic data  = FetchFormData();
                    string  phone = data.Phone;
                    string  vcode = data.VCode;
                    string  pwd   = data.Pwd;
                    string  msg   = string.Empty;
                    if (authobj.ResetPassword(phone, vcode, pwd, out msg))
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 1, Msg = "重置密码成功"
                        }));
                    }
                    else
                    {
                        return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 0, Msg = string.IsNullOrEmpty(msg) ? "重置失败" : msg
                        }));
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.WriteLog(ex);
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = ex.Message
                    }));
                }
            };

            Get["/CheckAppUpdateState"] = _ =>
            {
                try
                {
                    var    data        = FecthQueryData();
                    int    appid       = data.AppType;
                    string ver         = data.Version;
                    int    versionType = 0;
                    try
                    {
                        versionType = data.VersionType;
                    }
                    catch
                    {
                        versionType = 0;
                    }
                    AppUpdateEntity info  = new AppUpdateEntity();
                    bool            state = false;
                    if (versionType == 0)
                    {
                        state = commonobj.CheckAppUpdateState(appid, ver, out info);
                    }
                    else
                    {
                        state = commonobj.CheckAppUpdateState(appid, ver, versionType, out info);
                    }

                    if (state)
                    {
                        info.NeedUpdate = true;
                        return(JsonObj <JsonMessageBase <AppUpdateEntity> > .ToJson(new JsonMessageBase <AppUpdateEntity>() { Status = 1, Msg = "有新版本", Tag = "1", Value = info }));
                    }
                    else
                    {
                        return(JsonObj <JsonMessageBase <AppUpdateEntity> > .ToJson(new JsonMessageBase <AppUpdateEntity>() { Status = 1, Msg = "程序为最新版不需要更新", Tag = "0", Value = new AppUpdateEntity() }));
                    }
                }
                catch (Exception ex)
                {
                    return(JsonObj <JsonMessageBase <AppUpdateEntity> > .ToJson(new JsonMessageBase <AppUpdateEntity>() { Status = 0, Msg = ex.Message, Value = new AppUpdateEntity() }));
                }
            };

            #region  改变客户签到状态 2015/11/12
            Get["UpdateSignState"] = _ =>
            {
                dynamic data        = FecthQueryData();
                string  customerKey = data.CustomerKey;
                string  stateStr    = data.State;
                int     state       = 0;
                int.TryParse(stateStr, out state);
                IList <SignBookEntity> entity = BCtrl_SignBook.Instance.SignBook_Get(customerKey);
                if (entity == null)
                {
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = "数据查询异常,无法连接服务器"
                    }));
                }
                else if (entity.Count == 0)
                {
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = "不是有效报名用户,不能签到!"
                    }));
                }
                else if (entity[0].IsSign == 1)
                {
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = " 重复签到 " + entity[0].Company + "  " + entity[0].Customer
                    }));
                }
                bool flag = BCtrl_SignBook.Instance.SignBook_Update(customerKey, state);
                if (!flag)
                {
                    return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                    {
                        Status = 0, Msg = "数据查询异常,无法连接服务器"
                    }));
                }
                return(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                {
                    Status = 1, Msg = entity[0].Company + " " + entity[0].Customer + " 签到成功!"
                }));
            };
            #endregion
        }
Exemplo n.º 9
0
        public UserSessionEntity IsThereExistUser(string thridpart_username, string thirdpartuserid, int logintype, string url)
        {
            UserSessionEntity info = new UserSessionEntity();

            SqlParameter[] prms =
            {
                new SqlParameter("@LoginID",   thirdpartuserid),
                new SqlParameter("@LoginName", thridpart_username),
                new SqlParameter("@LoginType", logintype),
                new SqlParameter("@Url",       url)
            };
            string targetname = string.Empty;
            string targetid   = string.Empty;

            switch (logintype)
            {
            case 1:
                targetname = "ThirdWxUserName";
                targetid   = "ThirdWxID";
                break;

            case 2:
                targetname = "ThirdWbUserName";
                targetid   = "ThirdWbID";
                break;

            case 3:
                targetname = "ThirdQqUserNameW";
                targetid   = "ThirdQqID";
                break;
            }
            SqlTransaction trans = null;
            string         sql   = string.Format("select UserID,AreaID,Telphone,ThirdWxUserName,ThirdWbUserName,ThirdQqUserNameW,ThirdPictureUrl,p.PicturePath,p.Domain,NickName from M_User m left join M_V_Picture p on m.PictureID=p.PictureID where {0}=@LoginID and LoginType=@LoginType ", targetid);

            using (SqlConnection con = new SqlConnection(SQlHelper.MyConnectStr))
            {
                try
                {
                    con.Open();
                    trans = con.BeginTransaction();
                    DataTable dt = SQlHelper.ExecuteDataset(trans, CommandType.Text, sql, prms).Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        int userid = int.Parse(dt.Rows[0]["UserID"].ToString());

                        info.UserID           = userid;
                        info.ZoneID           = dt.Rows[0]["AreaID"].ToString() == "" ? 0 : int.Parse(dt.Rows[0]["AreaID"].ToString());
                        info.Telphone         = dt.Rows[0]["Telphone"].ToString();
                        info.ThirdWxUserName  = dt.Rows[0]["ThirdWxUserName"].ToString();
                        info.ThirdWbUserName  = dt.Rows[0]["ThirdWbUserName"].ToString();
                        info.ThirdQqUserNameW = dt.Rows[0]["ThirdQqUserNameW"].ToString();
                        info.NickName         = dt.Rows[0]["NickName"].ToString();
                        info.ThirdPictureUrl  = dt.Rows[0]["ThirdPictureUrl"].ToString();
                        info.PicturePath      = dt.Rows[0]["PicturePath"].ToString();
                        info.Domain           = dt.Rows[0]["Domain"].ToString();
                        trans.Commit();
                        return(info);
                    }
                }
                catch (Exception ex)
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    LogUtil.WriteLog(ex);
                    return(null);
                }
            }
            return(null);
        }
Exemplo n.º 10
0
        public UserSessionEntity TryLoginX(string thridpart_username, string thirdpartuserid, int logintype, string url)
        {
            UserSessionEntity info = new UserSessionEntity();

            SqlParameter[] prms =
            {
                new SqlParameter("@LoginID",   thirdpartuserid),
                new SqlParameter("@LoginName", thridpart_username),
                new SqlParameter("@LoginType", logintype),
                new SqlParameter("@Url",       url),
                new SqlParameter("@NickName",  thridpart_username)
            };
            string targetname = "";
            string targetid   = "";

            switch (logintype)
            {
            case 1:
                targetname = "ThirdWxUserName";
                targetid   = "ThirdWxID";
                break;

            case 2:
                targetname = "ThirdWbUserName";
                targetid   = "ThirdWbID";
                break;

            case 3:
                targetname = "ThirdQqUserNameW";
                targetid   = "ThirdQqID";
                break;
            }
            SqlTransaction trans = null;
            string         sql   = string.Format("select UserID,AreaID,Telphone,ThirdWxUserName,ThirdWbUserName,ThirdQqUserNameW,ThirdPictureUrl,p.PicturePath,p.Domain,NickName from M_User m left join M_V_Picture p on m.PictureID=p.PictureID where {0}=@LoginID  ", targetid);

            using (SqlConnection con = new SqlConnection(SQlHelper.MyConnectStr))
            {
                try
                {
                    con.Open();
                    trans = con.BeginTransaction();
                    DataTable dt = SQlHelper.ExecuteDataset(trans, CommandType.Text, sql, prms).Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        int userid = int.Parse(dt.Rows[0]["UserID"].ToString());

                        info.UserID           = userid;
                        info.ZoneID           = dt.Rows[0]["AreaID"].ToString() == "" ? 0 : int.Parse(dt.Rows[0]["AreaID"].ToString());
                        info.Telphone         = dt.Rows[0]["Telphone"].ToString();
                        info.ThirdWxUserName  = dt.Rows[0]["ThirdWxUserName"].ToString();
                        info.ThirdWbUserName  = dt.Rows[0]["ThirdWbUserName"].ToString();
                        info.ThirdQqUserNameW = dt.Rows[0]["ThirdQqUserNameW"].ToString();
                        info.NickName         = dt.Rows[0]["NickName"].ToString();

                        info.ThirdPictureUrl = dt.Rows[0]["ThirdPictureUrl"].ToString();
                        info.PicturePath     = dt.Rows[0]["PicturePath"].ToString();
                        info.Domain          = dt.Rows[0]["Domain"].ToString();
                        trans.Commit();
                        return(info);
                    }
                    else
                    {
                        sql = string.Format("insert into M_User(LoginName,PassWord,{0},{1},LoginType,ThirdPictureUrl,NickName) output inserted.UserID values('{2}','{3}',@LoginID,@LoginName,@LoginType,@Url,@NickName)",
                                            targetid, targetname, Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N"));
                        int userid = int.Parse(SQlHelper.ExecuteScalar(trans, CommandType.Text, sql, prms).ToString());
                        trans.Commit();
                        info.UserID   = userid;
                        info.NickName = thridpart_username;
                        info.ZoneID   = 0;
                        switch (logintype)
                        {
                        case 1:
                            info.ThirdWxUserName = thridpart_username;
                            break;

                        case 2:
                            info.ThirdWbUserName = thridpart_username;
                            break;

                        case 3:
                            info.ThirdQqUserNameW = thridpart_username;
                            break;
                        }
                        info.Domain = string.Empty;
                        if (string.IsNullOrEmpty(url))
                        {
                            url = "http://";
                        }
                        info.ThirdPictureUrl = url;
                        return(info);
                    }
                }
                catch (Exception ex)
                {
                    if (trans != null)
                    {
                        trans.Rollback();
                    }
                    LogUtil.WriteLog(ex);
                    return(null);
                }
            }
        }
Exemplo n.º 11
0
        public static bool Login(string username, string password)
        {
            bool result = false;
            var user = new UserEntity { Username = username, Password = password };
            var session = new UserSessionEntity { Username = username, SessionId = HttpContext.Current.Session.SessionID, IpAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString() };

            var response = WebApiHelper.SscCoreRequest("User/Login", new TheSscRequest(user, session) { AccessKey = Guid.NewGuid().ToString() });
            if (response.IsNotNull())
            {
                if (response.ResponseCode.Equals(TheSscResultCode.LoginSucceed))
                {
                    result = true;
                }
            }
            return result;
        }
Exemplo n.º 12
0
 public Task Delete(UserSessionEntity entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 13
0
        public async Task <UserSessionEntity> Add(UserSessionEntity entity)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(_coreDbContext.Database.GetDbConnection().ConnectionString))
                {
                    DynamicParameters parameters = new DynamicParameters();

                    parameters.Add("@UserID", entity.UserID);
                    parameters.Add("@Token", entity.Token);
                    parameters.Add("@NotBeforeDate", entity.NotBeforeDate);
                    parameters.Add("@ExpiresDate", entity.ExpiresDate);
                    parameters.Add("@LoginDate", entity.LoginDate);
                    parameters.Add("@LogoutDate", entity.LogoutDate);
                    parameters.Add("@StateID", entity.StateID);

                    parameters.Add("@IsActive", entity.IsActive);
                    parameters.Add("@IsVisible", entity.IsVisible);
                    parameters.Add("@IsDelete", entity.IsDelete);
                    parameters.Add("@ChangeType", entity.ChangeType);
                    parameters.Add("@HostnameCreated", entity.HostnameCreated);
                    parameters.Add("@IPAddressCreated", entity.IPAddressCreated);
                    parameters.Add("@CreatedBy", entity.CreatedBy);
                    parameters.Add("@CreateDate", entity.CreateDate);
                    parameters.Add("@HostnameUpdated", entity.HostnameUpdated);
                    parameters.Add("@IPAddressUpdated", entity.IPAddressUpdated);
                    parameters.Add("@UpdatedBy", entity.UpdatedBy);
                    parameters.Add("@UpdateDate", entity.UpdateDate);

                    parameters.Add("@ID", dbType: DbType.Int32, direction: ParameterDirection.Output, size: 5215585);
                    parameters.Add("@Code", dbType: DbType.Int64, direction: ParameterDirection.Output, size: 5215585);
                    parameters.Add("@ErrorMessage", dbType: DbType.String, direction: ParameterDirection.Output, size: 5215585);
                    parameters.Add("@ErrorCode", dbType: DbType.Int32, direction: ParameterDirection.Output, size: 5215585);

                    string query = "[dbo].[usp_ins_user_sessions]";

                    await connection.OpenAsync();

                    var result = await connection.ExecuteAsync(sql : query,
                                                               param : parameters,
                                                               commandType : CommandType.StoredProcedure);

                    var ErrorMessage = parameters.Get <string>("@ErrorMessage");
                    var ErrorCode    = parameters.Get <int>("@ErrorCode");

                    if (ErrorCode < 0 || !string.IsNullOrEmpty(ErrorMessage))
                    {
                        throw new Exception(ErrorMessage);
                    }

                    entity.ID   = parameters.Get <int>("@ID");
                    entity.Code = parameters.Get <long>("@Code");
                    return(entity);
                }
            }
            catch (SqlException sqlEx)
            {
                throw sqlEx;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 14
0
 public Task <UserSessionEntity> Update(int id, UserSessionEntity entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public Task <IEnumerable <UserSessionEntity> > Get(UserSessionEntity entity)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public Task <bool> Exist(UserSessionEntity entity)
 {
     throw new NotImplementedException();
 }