Ejemplo n.º 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);
        }
Ejemplo n.º 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
            }));
        }
        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);
        }
Ejemplo n.º 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
                }));
            }
        }
 public bool CreateUser(User user)
 {
     return(_usersIdentityRepository.Add(user));
 }
        public bool BlockUser(string userId)
        {
            var user = _blockedUsersRepository.Add(new BlockedUser(userId));

            return(user != null);
        }
Ejemplo n.º 7
0
 public TEntity Add(TEntity entity)
 {
     return(_repository.Add(entity));
 }