mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-07 18:03:48 +00:00
[user settings] improved 'edit avatar'
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { gettext, siteRoot } from '../../utils/constants';
|
import { gettext, siteRoot } from '../../utils/constants';
|
||||||
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
import toaster from '../toast';
|
import toaster from '../toast';
|
||||||
|
|
||||||
const { avatarURL, csrfToken } = window.app.pageOptions;
|
const { avatarURL, csrfToken } = window.app.pageOptions;
|
||||||
@@ -50,7 +51,25 @@ class UserAvatarForm extends React.Component {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.form.current.submit();
|
//this.form.current.submit();
|
||||||
|
seafileAPI.updateUserAvatar(file, 160).then((res) => {
|
||||||
|
this.setState({
|
||||||
|
avatarSrc: res.data.avatar_url
|
||||||
|
});
|
||||||
|
toaster.success(gettext('Success'));
|
||||||
|
}).catch((error) => {
|
||||||
|
let errorMsg = '';
|
||||||
|
if (error.response) {
|
||||||
|
if (error.response.data && error.response.data['error_msg']) {
|
||||||
|
errorMsg = error.response.data['error_msg'];
|
||||||
|
} else {
|
||||||
|
errorMsg = gettext('Error');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errorMsg = gettext('Please check the network.');
|
||||||
|
}
|
||||||
|
toaster.danger(errorMsg);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
openFileInput = () => {
|
openFileInput = () => {
|
||||||
@@ -75,7 +94,7 @@ class UserAvatarForm extends React.Component {
|
|||||||
<input type="hidden" name="csrfmiddlewaretoken" value={csrfToken} />
|
<input type="hidden" name="csrfmiddlewaretoken" value={csrfToken} />
|
||||||
<label className="col-sm-1 col-form-label">{gettext('Avatar:')}</label>
|
<label className="col-sm-1 col-form-label">{gettext('Avatar:')}</label>
|
||||||
<div className="col-auto position-relative" onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
|
<div className="col-auto position-relative" onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
|
||||||
<img src={avatarURL} width="80" height="80" alt="" className="user-avatar" />
|
<img src={this.state.avatarSrc} width="80" height="80" alt="" className="user-avatar" />
|
||||||
<input type="file" name="avatar" className="d-none" onChange={this.fileInputChange} ref={this.fileInput} />
|
<input type="file" name="avatar" className="d-none" onChange={this.fileInputChange} ref={this.fileInput} />
|
||||||
<span className={`avatar-edit fas fa-edit ${!this.state.isEditShown && 'd-none'}`} onClick={this.openFileInput}></span>
|
<span className={`avatar-edit fas fa-edit ${!this.state.isEditShown && 'd-none'}`} onClick={this.openFileInput}></span>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from rest_framework.authentication import SessionAuthentication
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
@@ -23,7 +24,7 @@ from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class UserAvatarView(APIView):
|
class UserAvatarView(APIView):
|
||||||
authentication_classes = (TokenAuthentication,)
|
authentication_classes = (TokenAuthentication, SessionAuthentication)
|
||||||
permission_classes = (IsAuthenticated,)
|
permission_classes = (IsAuthenticated,)
|
||||||
throttle_classes = (UserRateThrottle,)
|
throttle_classes = (UserRateThrottle,)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user