Esempio n. 1
0
        public LoginAccountPacketRes LoginAccount([FromBody] LoginAccountPacketReq req)
        {
            LoginAccountPacketRes res = new LoginAccountPacketRes();

            AccountDb account = _context.Accounts
                                .AsNoTracking()
                                .Where(a => a.AccountName == req.AccountName && a.Password == req.Password)
                                .FirstOrDefault();

            if (account == null)
            {
                res.LoginOk = false;
            }
            else
            {
                res.LoginOk = true;

                // Create Token
                DateTime expired = DateTime.UtcNow;
                expired.AddSeconds(600);

                TokenDb tokenDb = _shared.Tokens.Where(t => t.AccountDbId == account.AccountDbId).FirstOrDefault();
                if (tokenDb != null)
                {
                    tokenDb.Token   = new Random().Next(Int32.MinValue, Int32.MaxValue);
                    tokenDb.Expired = expired;
                    _shared.SaveChangesEx();
                }
                else
                {
                    tokenDb = new TokenDb()
                    {
                        AccountDbId = account.AccountDbId,
                        Token       = new Random().Next(Int32.MinValue, Int32.MaxValue),
                        Expired     = expired
                    };

                    _shared.Add(tokenDb);
                    _shared.SaveChangesEx();
                }

                res.AccountId  = account.AccountDbId;
                res.Token      = tokenDb.Token;
                res.ServerList = new List <ServerInfo>();

                foreach (ServerDb serverDb in _shared.Servers)
                {
                    res.ServerList.Add(new ServerInfo()
                    {
                        Name      = serverDb.Name,
                        IpAddress = serverDb.IpAddress,
                        Port      = serverDb.Port,
                        BusyScore = serverDb.BusyScore
                    });
                }
            }

            return(res);
        }
Esempio n. 2
0
 public UserController(IDb db, UserManager <User> userManager, Piranha.ISecurity service, TokenDb tokenDb, IEmailService emailService)
 {
     _db           = db;
     _userManager  = userManager;
     _service      = service;
     _tokenDb      = tokenDb;
     _emailService = emailService;
 }
Esempio n. 3
0
        public async Task <bool> AddTokenAsync(TokenDb token)
        {
            var existingToken =
                _context.TokensDb.SingleOrDefault(r => r.TokenId == token.TokenId);

            if (existingToken != null)
            {
                await RemoveTokenAsync(existingToken);
            }

            _context.TokensDb.Add(token);

            return(await _context.SaveChangesAsync() > 0);
        }
Esempio n. 4
0
        public WSR_Result GetAuthentication(WSR_Param param)
        {
            Token      token  = null;
            object     data   = null;
            WSR_Result result = null;

            result = VerifParamType(param, "token", out token);

            if (result == null)
            {
                token = (Token)param["token"];
                TokenDb db = new TokenDb();
                token = db.GetAuh(token);
                data  = token;
                return(new WSR_Result(data, true));
            }
            return(result);
        }
Esempio n. 5
0
 /// <summary>
 /// 更新登录信息
 /// </summary>
 /// <param name="login_Info"></param>
 /// <returns></returns>
 public bool Update(Entity.T_Token token)
 {
     return(TokenDb.Update(token));
 }
Esempio n. 6
0
 /// <summary>
 /// 返回相关的Token信息
 /// </summary>
 /// <param name="tokenId"></param>
 /// <returns></returns>
 public Entity.T_Token GetToken(string tokenId)
 {
     return(TokenDb.GetSingle(u => u.Token_id == tokenId));
 }
Esempio n. 7
0
 /// <summary>
 /// 通过用户ID获取已登录信息
 /// </summary>
 /// <param name="uid">用户ID</param>
 /// <returns></returns>
 public Entity.T_Token GetByUserId(int userId)
 {
     return(TokenDb.GetSingle(u => u.Token_user_id == userId));
 }
Esempio n. 8
0
 /// <summary>
 /// 通过用户ID删除
 /// </summary>
 /// <param name="userId">用户ID</param>
 /// <returns></returns>
 public bool Delete(int userId)
 {
     return(TokenDb.Delete(u => u.Token_user_id == userId));
 }
Esempio n. 9
0
 /// <summary>
 /// 通过TokenID删除
 /// </summary>
 /// <param name="tokenId">TokenID</param>
 /// <returns></returns>
 public bool Delete(string tokenId)
 {
     return(TokenDb.Delete(u => u.Token_id == tokenId));
 }
Esempio n. 10
0
 /// <summary>
 /// 插入数据
 /// </summary>
 /// <param name="login_Info"></param>
 /// <returns></returns>
 public bool Add(Entity.T_Token token)
 {
     return(TokenDb.Insert(token));
 }
Esempio n. 11
0
 public async Task <bool> RemoveTokenAsync(TokenDb refreshToken)
 {
     _context.TokensDb.Remove(refreshToken);
     return(await _context.SaveChangesAsync() > 0);
 }
Esempio n. 12
0
 public UserTokensEfDao(TokenDb db)
 {
     _db = db;
 }