Beispiel #1
0
        public string SignUp(string idToken)
        {
            GoogleResponseJson    response = new GoogleResponseJson();
            GoogleIdTokenVerifyer verifyer = new GoogleIdTokenVerifyer();

            response = verifyer.Verify(idToken);
            if (response.IsEmpty)
            {
                return(null);
            }
            User newUser = new User(response.sub);

            _userCollection.Add(response.sub, newUser);
            return(response.email);
        }
Beispiel #2
0
        public RegistrationResponse SignUp(string idToken)
        {
            GoogleResponseJson    response = new GoogleResponseJson();
            GoogleIdTokenVerifyer verifyer = new GoogleIdTokenVerifyer();

            response = verifyer.Verify(idToken);
            if (response.IsEmpty)
            {
                return(null);
            }

            if (response.email == null)
            {
                return(null);
            }

            var collection = db.GetCollection <User>("Users");

            var iUser = collection.FindSync(us => us.UserId == response.email);

            var result = iUser.FirstAsync();

            if (!result.IsFaulted)
            {
                User user = result.Result;
                return(new RegistrationResponse
                {
                    PicUrl = user.PictureUrl,
                    NicknameDateOfChange = user.NicknameDateOfChange,
                    UserId = user.UserId,
                    UserNickname = user.UserNickname
                });
            }
            DateTimeOffset date    = DateTimeOffset.Now;
            User           newUser = new User(response.email, response.picture, date);

            collection.InsertOne(newUser);
            RegistrationResponse toReturn = new RegistrationResponse
            {
                NicknameDateOfChange = date,
                PicUrl       = response.picture,
                UserId       = response.email,
                UserNickname = response.email
            };

            return(toReturn);
        }
Beispiel #3
0
        public RegistrationResponse SingIn(string googleToken)
        {
            var verifier = new GoogleIdTokenVerifyer();

            var response = verifier.Verify(googleToken);

            if (response.IsEmpty)
            {
                return(null);
            }

            if (response.email == null)
            {
                return(null);
            }

            var toReturn = _userRepository.AddOrFindUser(response);

            return(toReturn);
        }