Change /me to /user and allow email changes
This commit is contained in:
parent
56a187c576
commit
f50a3ca129
|
@ -43,26 +43,23 @@ def process_image(upload):
|
|||
return small, medium, large
|
||||
|
||||
|
||||
|
||||
class UserTrainingSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = models.Training
|
||||
exclude = ['user']
|
||||
depth = 2
|
||||
|
||||
class UserDetailsSerializer(UserDetailsSerializer):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username', 'email']
|
||||
|
||||
class UserSerializer(serializers.ModelSerializer):
|
||||
training = UserTrainingSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['id', 'username', 'email', 'member', 'transactions', 'cards', 'training']
|
||||
fields = ['id', 'username', 'member', 'transactions', 'cards', 'training']
|
||||
depth = 1
|
||||
|
||||
|
||||
|
||||
# member viewing member list or other member
|
||||
class OtherMemberSerializer(serializers.ModelSerializer):
|
||||
q = serializers.CharField(write_only=True, max_length=64)
|
||||
|
@ -72,9 +69,16 @@ class OtherMemberSerializer(serializers.ModelSerializer):
|
|||
model = models.Member
|
||||
fields = ['q', 'seq', 'id', 'preferred_name', 'last_name', 'status', 'current_start_date', 'photo_small', 'photo_large']
|
||||
|
||||
class UserEmailField(serializers.ModelField):
|
||||
def to_representation(self, obj):
|
||||
return obj.user.email
|
||||
def to_internal_value(self, data):
|
||||
return serializers.EmailField().run_validation(data)
|
||||
|
||||
# member viewing himself
|
||||
class MemberSerializer(serializers.ModelSerializer):
|
||||
photo = serializers.ImageField(write_only=True, required=False)
|
||||
email = UserEmailField(serializers.EmailField)
|
||||
class Meta:
|
||||
model = models.Member
|
||||
fields = '__all__'
|
||||
|
@ -95,6 +99,9 @@ class MemberSerializer(serializers.ModelSerializer):
|
|||
]
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
instance.user.email = validated_data.get('email', instance.user.email)
|
||||
instance.user.save()
|
||||
|
||||
photo = validated_data.get('photo', None)
|
||||
if photo:
|
||||
small, medium, large = process_image(photo)
|
||||
|
@ -104,7 +111,6 @@ class MemberSerializer(serializers.ModelSerializer):
|
|||
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
|
||||
# adming viewing member
|
||||
class AdminMemberSerializer(MemberSerializer):
|
||||
class Meta:
|
||||
|
@ -119,6 +125,7 @@ class AdminMemberSerializer(MemberSerializer):
|
|||
]
|
||||
|
||||
|
||||
|
||||
class TransactionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = models.Transaction
|
||||
|
|
|
@ -123,7 +123,7 @@ class SessionViewSet(viewsets.ModelViewSet):
|
|||
return serializers.SessionSerializer
|
||||
|
||||
|
||||
class MyUserView(views.APIView):
|
||||
class UserView(views.APIView):
|
||||
permission_classes = [AllowMetadata | IsAuthenticated]
|
||||
|
||||
def get(self, request):
|
||||
|
|
|
@ -175,10 +175,6 @@ REST_FRAMEWORK = {
|
|||
'DEFAULT_AUTHENTICATION_CLASSES': DEFAULT_AUTHENTICATION_CLASSES,
|
||||
}
|
||||
|
||||
REST_AUTH_SERIALIZERS = {
|
||||
'USER_DETAILS_SERIALIZER': 'apiserver.api.serializers.UserDetailsSerializer'
|
||||
}
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'formatters': {
|
||||
|
|
|
@ -21,5 +21,5 @@ urlpatterns = [
|
|||
url(r'^rest-auth/', include('rest_auth.urls')),
|
||||
url(r'^registration/', views.RegistrationView.as_view(), name='rest_name_register'),
|
||||
url(r'^password/change/', views.PasswordChangeView.as_view(), name='rest_password_change'),
|
||||
url(r'^me/', views.MyUserView.as_view(), name='fullmember'),
|
||||
url(r'^user/', views.UserView.as_view(), name='user'),
|
||||
]
|
||||
|
|
|
@ -28,7 +28,7 @@ function App() {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
requester('/me/', 'GET', token)
|
||||
requester('/user/', 'GET', token)
|
||||
.then(res => {
|
||||
console.log(res);
|
||||
setUserCache(res);
|
||||
|
@ -49,6 +49,7 @@ function App() {
|
|||
<Router>
|
||||
<div className='content-wrap'>
|
||||
<div className='content-wrap-inside'>
|
||||
|
||||
<Container>
|
||||
<div className='hero'>
|
||||
<img src='/logo-long.svg' className='logo-long' />
|
||||
|
@ -176,6 +177,7 @@ function App() {
|
|||
</Route>
|
||||
}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import App from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
//import * as serviceWorker from './serviceWorker';
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById('root'));
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
||||
// unregister() to register() below. Note this comes with some pitfalls.
|
||||
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||
serviceWorker.unregister();
|
||||
// serviceWorker.unregister();
|
||||
|
|
|
@ -55,6 +55,10 @@ export const requester = (route, method, token, data) => {
|
|||
} else if (code >= 400 && code < 500) {
|
||||
return error.data.json()
|
||||
.then(result => {
|
||||
if (result.detail == 'Invalid token.') {
|
||||
localStorage.clear();
|
||||
window.location = '/';
|
||||
}
|
||||
throw customError(result);
|
||||
});
|
||||
} else if (code >= 500 && code < 600) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user