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 *
from .user import *
from .topic import *
from .star import *
from .account import *
urlpatterns = [
# 登陆,注销相关
url(r'account/login$', LoginView.as_view()),
url(r'account/logout', LogoutView.as_view()),
# user相关
url(r'user/list$', UserListView.as_view()),
......
......@@ -6,7 +6,7 @@ export function loginByUsername(username, password) {
password
}
return request({
url: '/login/login',
url: '/api/account/login',
method: 'post',
data
})
......@@ -14,7 +14,7 @@ export function loginByUsername(username, password) {
export function logout() {
return request({
url: '/login/logout',
url: '/api/account/logout',
method: 'post'
})
}
......
......@@ -10,6 +10,7 @@ export function fetchList(query) {
export function OffLineOrOnLine(data) {
console.log(data)
return request({
url: '/api/pick/update_or_create',
method: 'post',
......
......@@ -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(/\/user\/info\.*/, 'get', loginAPI.getUserInfo)
......
......@@ -49,7 +49,7 @@ const user = {
const username = userInfo.username.trim()
return new Promise((resolve, reject) => {
loginByUsername(username, userInfo.password).then(response => {
const data = response.data
const data = response.data.data
commit('SET_TOKEN', data.token)
setToken(response.data.token)
resolve()
......
......@@ -16,7 +16,6 @@
<size-select class="international right-menu-item"/>
</el-tooltip>
<lang-select class="international right-menu-item"/>
<el-tooltip :content="$t('navbar.theme')" effect="dark" placement="bottom">
<theme-picker class="theme-switch right-menu-item"/>
......@@ -31,16 +30,16 @@
<el-dropdown-menu slot="dropdown">
<router-link to="/">
<el-dropdown-item>
{{ $t('navbar.dashboard') }}
账号中心
</el-dropdown-item>
</router-link>
<a target="_blank" href="https://github.com/PanJiaChen/vue-element-admin/">
<el-dropdown-item>
{{ $t('navbar.github') }}
修改密码
</el-dropdown-item>
</a>
<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-menu>
</el-dropdown>
......@@ -55,7 +54,6 @@ import Hamburger from '@/components/Hamburger'
import ErrorLog from '@/components/ErrorLog'
import Screenfull from '@/components/Screenfull'
import SizeSelect from '@/components/SizeSelect'
import LangSelect from '@/components/LangSelect'
import ThemePicker from '@/components/ThemePicker'
export default {
......@@ -65,7 +63,6 @@ export default {
ErrorLog,
Screenfull,
SizeSelect,
LangSelect,
ThemePicker
},
computed: {
......
......@@ -4,8 +4,7 @@
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
<div class="title-container">
<h3 class="title">{{ $t('login.title') }}</h3>
<lang-select class="set-language"/>
<h3 class="title">更美社区后台</h3>
</div>
<el-form-item prop="username">
......@@ -36,40 +35,17 @@
<svg-icon icon-class="eye" />
</span>
</el-form-item>
<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-dialog :title="$t('login.thirdparty')" :visible.sync="showDialog" append-to-body>
{{ $t('login.thirdpartyTips') }}
<br>
<br>
<br>
<social-sign />
</el-dialog>
</div>
</template>
<script>
import { isvalidUsername } from '@/utils/validate'
import LangSelect from '@/components/LangSelect'
import SocialSign from './socialsignin'
export default {
name: 'Login',
components: { LangSelect, SocialSign },
data() {
const validateUsername = (rule, value, callback) => {
if (!isvalidUsername(value)) {
......@@ -88,7 +64,7 @@ export default {
return {
loginForm: {
username: 'admin',
password: '1111111'
password: '123123'
},
loginRules: {
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
......@@ -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>
......
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