コード例 #1
0
        public string GenerateKey(string userId, string username, bool isAdmin = false, string facebookToken = null)
        {
            int  ttl = int.Parse(ConfigurationManager.AppSettings["TokenTTL"]);
            long exp = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + 60 * ttl;
            long iat = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            var payload = new Dictionary <string, object>()
            {
                { "sub", userId },
                { "exp", exp },
                { "iat", iat },
                { "aud", "social network" },
                { "username", username },
                { "isAdmin", isAdmin }
            };


            string key = ConfigurationManager.AppSettings["tokenSignKey"];

            byte[] secretKey = Encoding.ASCII.GetBytes(key);
            string token     = JWT.Encode(payload, secretKey, JwsAlgorithm.HS256);

            TokenHistory history = new TokenHistory()
            {
                Token = token, FacebookToken = facebookToken, UserId = userId, TimeStamp = iat
            };

            _tokenReposirory.Add(history);

            return(token);
        }
コード例 #2
0
        public UserAuth Register(RegisterDTO model)
        {
            var    guid     = Guid.NewGuid().ToString();
            string passHash = PasswordHasher.Hash(model.Password);

            return(_authRepository.Add(new UserAuth()
            {
                Username = model.Username, Password = passHash, UserId = guid
            }));
        }
コード例 #3
0
        public void AddToHistory(string UserId, string methood, object pyload)
        {
            long         timeStamp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
            Notification item      = new Notification()
            {
                UserId    = UserId,
                TimeStamp = timeStamp,
                DataJson  = JsonConvert.SerializeObject(pyload)
            };

            _notificationsRepository.Add(item);
        }
コード例 #4
0
        public UserFacebook LoginFacebook(FacebookLoginDTO model)
        {
            var existingUser = _oAuthRepository.Get(model.FacebookId);

            if (existingUser != null)
            {
                if (IsBlocked(existingUser.UserId))
                {
                    throw new UserBlockedException();
                }
                return(existingUser);
            }
            else
            {
                var guid = Guid.NewGuid().ToString();
                return(_oAuthRepository.Add(new UserFacebook()
                {
                    FacebookId = model.FacebookId, Username = model.Username, UserId = guid
                }));
            }
        }
コード例 #5
0
 public bool CreateUser(User user)
 {
     return(_usersIdentityRepository.Add(user));
 }
コード例 #6
0
        public bool BlockUser(string userId)
        {
            var user = _blockedUsersRepository.Add(new BlockedUser(userId));

            return(user != null);
        }
コード例 #7
0
 public TEntity Add(TEntity entity)
 {
     return(_repository.Add(entity));
 }