Commit 69fac6b5 authored by Davve's avatar Davve

增加登陆登出功能

parent c667d57b
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "chenwei"
# Date: 2018/11/16
from utils.base import APIView
class LoginView(APIView):
def post(self, request):
username = request.POST.get('username')
password = request.POST.get('password')
if username == 'admin' and password == '123123':
return {
'roles': ['admin'],
'token': 'admin',
'introduction': '我是超级管理员',
'avatar': 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
'name': 'Super Admin'
}
else:
return {
'roles': ['editor'],
'token': 'editor',
'introduction': '我是编辑',
'avatar': 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
'name': 'Normal Editor'
}
class LogoutView(APIView):
def post(self, request):
pass
\ No newline at end of file
...@@ -12,8 +12,12 @@ from .group import * ...@@ -12,8 +12,12 @@ from .group import *
from .user import * from .user import *
from .topic import * from .topic import *
from .star import * from .star import *
from .account import *
urlpatterns = [ urlpatterns = [
# 登陆,注销相关
url(r'account/login$', LoginView.as_view()),
url(r'account/logout', LogoutView.as_view()),
# user相关 # user相关
url(r'user/list$', UserListView.as_view()), url(r'user/list$', UserListView.as_view()),
......
...@@ -6,7 +6,7 @@ export function loginByUsername(username, password) { ...@@ -6,7 +6,7 @@ export function loginByUsername(username, password) {
password password
} }
return request({ return request({
url: '/login/login', url: '/api/account/login',
method: 'post', method: 'post',
data data
}) })
...@@ -14,7 +14,7 @@ export function loginByUsername(username, password) { ...@@ -14,7 +14,7 @@ export function loginByUsername(username, password) {
export function logout() { export function logout() {
return request({ return request({
url: '/login/logout', url: '/api/account/logout',
method: 'post' method: 'post'
}) })
} }
......
...@@ -10,6 +10,7 @@ export function fetchList(query) { ...@@ -10,6 +10,7 @@ export function fetchList(query) {
export function OffLineOrOnLine(data) { export function OffLineOrOnLine(data) {
console.log(data)
return request({ return request({
url: '/api/pick/update_or_create', url: '/api/pick/update_or_create',
method: 'post', method: 'post',
......
...@@ -19,7 +19,7 @@ Mock.XHR.prototype.send = function() { ...@@ -19,7 +19,7 @@ Mock.XHR.prototype.send = function() {
// }) // })
// 登录相关 // 登录相关
Mock.mock(/\/login\/login/, 'post', loginAPI.loginByUsername) // Mock.mock(/\/login\/login/, 'post', loginAPI.loginByUsername)
Mock.mock(/\/login\/logout/, 'post', loginAPI.logout) Mock.mock(/\/login\/logout/, 'post', loginAPI.logout)
Mock.mock(/\/user\/info\.*/, 'get', loginAPI.getUserInfo) Mock.mock(/\/user\/info\.*/, 'get', loginAPI.getUserInfo)
......
...@@ -49,7 +49,7 @@ const user = { ...@@ -49,7 +49,7 @@ const user = {
const username = userInfo.username.trim() const username = userInfo.username.trim()
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
loginByUsername(username, userInfo.password).then(response => { loginByUsername(username, userInfo.password).then(response => {
const data = response.data const data = response.data.data
commit('SET_TOKEN', data.token) commit('SET_TOKEN', data.token)
setToken(response.data.token) setToken(response.data.token)
resolve() resolve()
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
<size-select class="international right-menu-item"/> <size-select class="international right-menu-item"/>
</el-tooltip> </el-tooltip>
<lang-select class="international right-menu-item"/>
<el-tooltip :content="$t('navbar.theme')" effect="dark" placement="bottom"> <el-tooltip :content="$t('navbar.theme')" effect="dark" placement="bottom">
<theme-picker class="theme-switch right-menu-item"/> <theme-picker class="theme-switch right-menu-item"/>
...@@ -31,16 +30,16 @@ ...@@ -31,16 +30,16 @@
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<router-link to="/"> <router-link to="/">
<el-dropdown-item> <el-dropdown-item>
{{ $t('navbar.dashboard') }} 账号中心
</el-dropdown-item> </el-dropdown-item>
</router-link> </router-link>
<a target="_blank" href="https://github.com/PanJiaChen/vue-element-admin/"> <a target="_blank" href="https://github.com/PanJiaChen/vue-element-admin/">
<el-dropdown-item> <el-dropdown-item>
{{ $t('navbar.github') }} 修改密码
</el-dropdown-item> </el-dropdown-item>
</a> </a>
<el-dropdown-item divided> <el-dropdown-item divided>
<span style="display:block;" @click="logout">{{ $t('navbar.logOut') }}</span> <span style="display:block;" @click="logout">退出账户</span>
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</el-dropdown> </el-dropdown>
...@@ -55,7 +54,6 @@ import Hamburger from '@/components/Hamburger' ...@@ -55,7 +54,6 @@ import Hamburger from '@/components/Hamburger'
import ErrorLog from '@/components/ErrorLog' import ErrorLog from '@/components/ErrorLog'
import Screenfull from '@/components/Screenfull' import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect' import SizeSelect from '@/components/SizeSelect'
import LangSelect from '@/components/LangSelect'
import ThemePicker from '@/components/ThemePicker' import ThemePicker from '@/components/ThemePicker'
export default { export default {
...@@ -65,7 +63,6 @@ export default { ...@@ -65,7 +63,6 @@ export default {
ErrorLog, ErrorLog,
Screenfull, Screenfull,
SizeSelect, SizeSelect,
LangSelect,
ThemePicker ThemePicker
}, },
computed: { computed: {
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left"> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
<div class="title-container"> <div class="title-container">
<h3 class="title">{{ $t('login.title') }}</h3> <h3 class="title">更美社区后台</h3>
<lang-select class="set-language"/>
</div> </div>
<el-form-item prop="username"> <el-form-item prop="username">
...@@ -36,40 +35,17 @@ ...@@ -36,40 +35,17 @@
<svg-icon icon-class="eye" /> <svg-icon icon-class="eye" />
</span> </span>
</el-form-item> </el-form-item>
<el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">{{ $t('login.logIn') }}</el-button> <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">{{ $t('login.logIn') }}</el-button>
<div class="tips">
<span>{{ $t('login.username') }} : admin</span>
<span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
</div>
<div class="tips">
<span style="margin-right:18px;">{{ $t('login.username') }} : editor</span>
<span>{{ $t('login.password') }} : {{ $t('login.any') }}</span>
</div>
<el-button class="thirdparty-button" type="primary" @click="showDialog=true">{{ $t('login.thirdparty') }}</el-button>
</el-form> </el-form>
<el-dialog :title="$t('login.thirdparty')" :visible.sync="showDialog" append-to-body>
{{ $t('login.thirdpartyTips') }}
<br>
<br>
<br>
<social-sign />
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { isvalidUsername } from '@/utils/validate' import { isvalidUsername } from '@/utils/validate'
import LangSelect from '@/components/LangSelect'
import SocialSign from './socialsignin'
export default { export default {
name: 'Login', name: 'Login',
components: { LangSelect, SocialSign },
data() { data() {
const validateUsername = (rule, value, callback) => { const validateUsername = (rule, value, callback) => {
if (!isvalidUsername(value)) { if (!isvalidUsername(value)) {
...@@ -88,7 +64,7 @@ export default { ...@@ -88,7 +64,7 @@ export default {
return { return {
loginForm: { loginForm: {
username: 'admin', username: 'admin',
password: '1111111' password: '123123'
}, },
loginRules: { loginRules: {
username: [{ required: true, trigger: 'blur', validator: validateUsername }], username: [{ required: true, trigger: 'blur', validator: validateUsername }],
...@@ -139,24 +115,6 @@ export default { ...@@ -139,24 +115,6 @@ export default {
} }
}) })
}, },
afterQRScan() {
// const hash = window.location.hash.slice(1)
// const hashObj = getQueryObject(hash)
// const originUrl = window.location.origin
// history.replaceState({}, '', originUrl)
// const codeMap = {
// wechat: 'code',
// tencent: 'code'
// }
// const codeName = hashObj[codeMap[this.auth_type]]
// if (!codeName) {
// alert('第三方登录失败')
// } else {
// this.$store.dispatch('LoginByThirdparty', codeName).then(() => {
// this.$router.push({ path: '/' })
// })
// }
}
} }
} }
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment