Beispiel #1
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="imei">if null then get new pid</param>
        /// <param name="isNew"></param>
        /// <param name="encodeFunc"></param>
        /// <returns></returns>
        public static string[] GetRegPassport(string imei, bool isNew = false, Func<string, string> encodeFunc = null)
        {
            if (!SnsCenterUser.CheckDevice(imei))
                throw (new Exception("禁止登入"));
            var list = new List<string>();
            SnsUser user = new SnsCenterUser().GetUserByDeviceId(imei);
            string passportId = string.Empty;

            if (!isNew && user.UserId > 0)
            {
                passportId = user.PassportId;
                if (user.RegType == RegType.Guest)
                {
                    //客户端换包重新获取游客账号,密码需要重置 
                    string password = GetRandomPwd();
                    user.Password = encodeFunc != null ? encodeFunc(password) : password;
                    var sns = new SnsCenterUser(user.PassportId, password, imei);
                    sns.ChangePass(user.UserId.ToString(), true);
                }
                else
                {
                    if (encodeFunc != null) user.Password = encodeFunc(user.Password);
                }
                list.Add(passportId);
                list.Add(user.Password);
            }
            else
            {
                PassportExpired passportExpired;
                if (isNew || !imeiMap.TryGetValue(imei, out passportExpired))
                {
                    passportId = new SnsPassport().GetRegPassport();
                    imeiMap[passportId] = new PassportExpired(passportId);
                }
                else
                {
                    passportId = passportExpired.Pid;
                    if (passportExpired.ExpiredTime < DateTime.Now)
                    {
                        //过期移除
                        imeiMap.TryRemove(imei, out passportExpired);
                    }
                    //检查超出
                    List<string> expiredMap;
                    if (imeiMap.Count > 100 && ((expiredMap = imeiMap.Where(t => t.Value.ExpiredTime < DateTime.Now).Select(t => t.Key).ToList()).Count > 10))
                    {
                        foreach (var expired in expiredMap)
                        {
                            imeiMap.TryRemove(expired, out passportExpired);
                        }
                    }
                }

                string password = GetRandomPwd();
                if (encodeFunc != null) password = encodeFunc(password);
                list.Add(passportId);
                list.Add(password);
            }
            return list.ToArray();
        }
Beispiel #2
0
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <param name="user"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static int ChangePass(string user, string password)
 {
     SnsCenterUser snsCenterUser = new SnsCenterUser(user, password, string.Empty);
     return snsCenterUser.ChangePass(user);
 }
Beispiel #3
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static int ChangePass(string user, string password)
        {
            SnsCenterUser snsCenterUser = new SnsCenterUser(user, password, string.Empty);

            return(snsCenterUser.ChangePass(user));
        }
Beispiel #4
0
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <param name="user"></param>
 /// <param name="password"></param>
 /// <param name="imei"></param>
 /// <returns></returns>
 public static int ChangePass(string user, string password, string imei = "")
 {
     SnsCenterUser snsCenterUser = new SnsCenterUser(user, password, imei);
     return snsCenterUser.ChangePass(user);
 }
Beispiel #5
0
        /// <summary>
        /// 获取通行证
        /// </summary>
        /// <param name="imei">if null then get new pid</param>
        /// <param name="isNew"></param>
        /// <param name="encodeFunc"></param>
        /// <returns></returns>
        public static string[] GetRegPassport(string imei, bool isNew = false, Func <string, string> encodeFunc = null)
        {
            if (!SnsCenterUser.CheckDevice(imei))
            {
                throw (new Exception("禁止登入"));
            }
            var     list       = new List <string>();
            SnsUser user       = new SnsCenterUser().GetUserByDeviceId(imei);
            string  passportId = string.Empty;

            if (!isNew && user.UserId > 0)
            {
                passportId = user.PassportId;
                if (user.RegType == RegType.Guest)
                {
                    //客户端换包重新获取游客账号,密码需要重置
                    string password = GetRandomPwd();
                    user.Password = encodeFunc != null?encodeFunc(password) : password;

                    var sns = new SnsCenterUser(user.PassportId, password, imei);
                    sns.ChangePass(user.UserId.ToString(), true);
                }
                else
                {
                    if (encodeFunc != null)
                    {
                        user.Password = encodeFunc(user.Password);
                    }
                }
                list.Add(passportId);
                list.Add(user.Password);
            }
            else
            {
                PassportExpired passportExpired;
                if (isNew || !imeiMap.TryGetValue(imei, out passportExpired))
                {
                    passportId = new SnsPassport().GetRegPassport();
                    if (!string.IsNullOrEmpty(imei))
                    {
                        imeiMap[imei] = new PassportExpired(passportId);
                    }
                }
                else
                {
                    passportId = passportExpired.Pid;
                    if (passportExpired.ExpiredTime < DateTime.Now)
                    {
                        //过期移除
                        imeiMap.TryRemove(imei, out passportExpired);
                    }
                    //检查超出
                    List <string> expiredMap;
                    if (imeiMap.Count > 100 && ((expiredMap = imeiMap.Where(t => t.Value.ExpiredTime < DateTime.Now).Select(t => t.Key).ToList()).Count > 10))
                    {
                        foreach (var expired in expiredMap)
                        {
                            imeiMap.TryRemove(expired, out passportExpired);
                        }
                    }
                }

                string password = GetRandomPwd();
                if (encodeFunc != null)
                {
                    password = encodeFunc(password);
                }
                list.Add(passportId);
                list.Add(password);
            }
            return(list.ToArray());
        }
Beispiel #6
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <param name="imei"></param>
        /// <returns></returns>
        public static int ChangePass(string user, string password, string imei = "")
        {
            SnsCenterUser snsCenterUser = new SnsCenterUser(user, password, imei);

            return(snsCenterUser.ChangePass(user));
        }