示例#1
0
        public async Task <IActionResult> FacebookCode(string code, string state)
        {
            MeResponse meResponse = null;

            if (!string.IsNullOrEmpty(code))
            {
                meResponse = await WebApiHelper.GetFacebookUserFromCodeAsync(code, state, _configuration);
            }
            else
            {
                return(BadRequest());
            }

            var user = await _context.Users.Where(a => a.EmailAddress == meResponse.email).FirstOrDefaultAsync();

            if (user == null)
            {
                var res = await Register(meResponse.email, "", LoginType.Facebook);

                return(Redirect($"https://localhost:5081/login?token={res.Message}"));
            }
            else
            {
                if (user.LoginType == 2) // 2 ==>> LoginType.Facebook
                {
                    var token = await GenerateToken2(user.UserId);

                    return(Redirect($"https://localhost:5081/login?token={token}&sss=(rrr)"));
                }
            }

            return(Redirect("https://localhost:5081/login?error=Email already exist"));
        }
示例#2
0
        public async Task <MessageAndStatusAndData <TokenAndEmailData> > FacebookToken(string access_token, string state)
        {
            MeResponse meResponse = null;

            if (!string.IsNullOrEmpty(access_token))
            {
                meResponse = await WebApiHelper.GetFacebookUserFromTokenAsync(access_token, state, _configuration);
            }
            else
            {
                return(new MessageAndStatusAndData <TokenAndEmailData>(null, "Some Errors", true));
            }

            var user = await _context.Users.Where(a => a.EmailAddress == meResponse.email).FirstOrDefaultAsync();

            if (user == null)
            {
                var res = await Register(meResponse.email, "", LoginType.Facebook);

                return(new MessageAndStatusAndData <TokenAndEmailData>(

                           new TokenAndEmailData {
                    Token = res.Message, Email = user.EmailAddress
                }
                           , "", false));
            }
            else
            {
                if (user.LoginType == 2)
                {
                    var token = await GenerateToken2(user.UserId);

                    return(new MessageAndStatusAndData <TokenAndEmailData>(

                               new TokenAndEmailData {
                        Token = token, Email = user.EmailAddress
                    }
                               , null, false));
                }
            }

            return(new MessageAndStatusAndData <TokenAndEmailData>(null, "User Exist", true));
        }