|
10 | 10 | from drf_user import user_settings |
11 | 11 | from drf_user.models import User |
12 | 12 | from drf_user.utils import check_validation |
13 | | -from drf_user.variables import EMAIL |
14 | | -from drf_user.variables import MOBILE |
| 13 | +from drf_user.constants import EMAIL, MOBILE |
15 | 14 |
|
16 | 15 |
|
17 | 16 | class UserSerializer(serializers.ModelSerializer): |
@@ -203,8 +202,7 @@ def validate(self, attrs: dict) -> dict: |
203 | 202 | if "email" not in attrs.keys() and "verify_otp" not in attrs.keys(): |
204 | 203 | raise serializers.ValidationError( |
205 | 204 | _( |
206 | | - "email field is compulsory while verifying a" |
207 | | - " non-existing user's OTP." |
| 205 | + "Email field is compulsory while verifying a non-existing user's OTP." |
208 | 206 | ) |
209 | 207 | ) |
210 | 208 | else: |
@@ -250,26 +248,27 @@ def get_user(email: str, mobile: str): |
250 | 248 | except User.DoesNotExist: |
251 | 249 | try: |
252 | 250 | user = User.objects.get(mobile=mobile) |
253 | | - except User.DoesNotExist: |
254 | | - user = None |
| 251 | + except User.DoesNotExist as e: |
| 252 | + raise NotFound( |
| 253 | + _(f"No user exists either for email={email} or mobile={mobile}") |
| 254 | + ) from e |
255 | 255 |
|
256 | | - if user: |
257 | | - if user.email != email: |
258 | | - raise serializers.ValidationError( |
259 | | - _( |
260 | | - "Your account is registered with {mobile} does not has " |
261 | | - "{email} as registered email. Please login directly via " |
262 | | - "OTP with your mobile.".format(mobile=mobile, email=email) |
263 | | - ) |
| 256 | + if user.email != email: |
| 257 | + raise serializers.ValidationError( |
| 258 | + _( |
| 259 | + "Your account is registered with {mobile} does not has " |
| 260 | + "{email} as registered email. Please login directly via " |
| 261 | + "OTP with your mobile.".format(mobile=mobile, email=email) |
264 | 262 | ) |
265 | | - if user.mobile != mobile: |
266 | | - raise serializers.ValidationError( |
267 | | - _( |
268 | | - "Your account is registered with {email} does not has " |
269 | | - "{mobile} as registered mobile. Please login directly via " |
270 | | - "OTP with your email.".format(mobile=mobile, email=email) |
271 | | - ) |
| 263 | + ) |
| 264 | + if user.mobile != mobile: |
| 265 | + raise serializers.ValidationError( |
| 266 | + _( |
| 267 | + "Your account is registered with {email} does not has " |
| 268 | + "{mobile} as registered mobile. Please login directly via " |
| 269 | + "OTP with your email.".format(mobile=mobile, email=email) |
272 | 270 | ) |
| 271 | + ) |
273 | 272 | return user |
274 | 273 |
|
275 | 274 | def validate(self, attrs: dict) -> dict: |
|
0 commit comments