def create(self, validated_data): key = validated_data['key'] try: token = TemporaryToken.objects.get(key=key) user_object = token.user user = NormalUserCreateSerializer(user_object) except TemporaryToken.DoesNotExist: raise customexception.AuthenticateException('Invalid token') if token.expired: token.delete() raise customexception.AuthenticateException('Token has expired') else: token.expires = timezone.now() + timezone.timedelta( minutes=settings.REST_FRAMEWORK_TEMPORARY_TOKENS['MINUTES']) return user
def check_google(access_token): url = 'https://www.googleapis.com/oauth2/v3/tokeninfo' params = { 'access_token': access_token } response = requests.get(url, params=params) response_dict = response.json() print(response_dict) print(settings.CONFIG_FILE['google']['client-id'].values()) if 'aud' in response_dict.keys(): if response_dict['aud'] in settings.CONFIG_FILE['google']['client-id'].values(): return True else: raise customexception.AuthenticateException('Invalid Access Token') else: raise customexception.AuthenticateException('Invalid Access Token')
def create(self, validated_data): username = validated_data['username'] password = validated_data['password'] user_object = authenticate(username=username, password=password) if user_object is None: raise customexception.AuthenticateException('Username or Password is wrong') return user_object
def create(self, validated_data): access_token_validation = CheckSocialAccessToken.check_google(access_token=validated_data['access_token']) if access_token_validation: user = Member(**validated_data) user.save() else: raise customexception.AuthenticateException('Invalid Access Token') return user
def create(self, validated_data): user_object = self.context['request'].user change_password1 = validated_data['change_password1'] change_password2 = validated_data['change_password2'] if change_password1 == change_password2 and len(change_password1) > 7: user_object.set_password(change_password1) user_object.save() return True else: raise customexception.AuthenticateException('Password does not match or too short password')
def create(self, validated_data): username = validated_data['username'] access_token = validated_data['access_token'] access_token_is_valid = CheckSocialAccessToken.check_google(access_token) if access_token_is_valid: user_object = Member.objects.get(username=username) user_object.access_token = access_token user_object.save() return user_object else: raise customexception.AuthenticateException('Invalid Access Token')
def create(self, validated_data): username = validated_data.pop('username', None) password = validated_data.pop('password', None) access_key = validated_data.pop('access_key', None) if username and password: user_object = authenticate(username=username, password=password) if user_object is None: raise customexception.AuthenticateException( '이메일 혹은 비밀번호를 확인해 주세요.') else: username = CheckSocialAccessToken.check_facebook(access_key) user_object = Member.objects.get(username=username) return user_object
def check_facebook(access_token): url = 'https://graph.facebook.com/debug_token' param = { 'input_token': access_token, 'access_token': settings.CONFIG_FILE['facebook']['app-access-token'] } response = requests.get(url, params=param) response_dict = response.json() is_valid = response_dict['data']['is_valid'] if is_valid: pass else: raise customexception.AuthenticateException('Invalid Access Token') return is_valid