login and register
This commit is contained in:
@@ -1,22 +1,50 @@
|
||||
const express = require('express');
|
||||
const loginRoute = expressRouter();
|
||||
const loginRoute = express.Router();
|
||||
|
||||
let LInfo = require('./user.model');
|
||||
|
||||
postRoutes.route('/login').post(function (req, res) {
|
||||
console.log(req);
|
||||
var user = req.body.username;
|
||||
var pass = req.body.password;
|
||||
LInfo.findOne(
|
||||
{
|
||||
and: [{username: user}, {password: pass}]
|
||||
},
|
||||
loginRoute.route('/add').post(function (req, res) {
|
||||
console.log(req.body);
|
||||
var username = req.body.user;
|
||||
LInfo.findOne({user: username},
|
||||
function(err, user){
|
||||
console.log(user);
|
||||
if(user == null){
|
||||
let post = new LInfo(req.body);
|
||||
console.log(post);
|
||||
post.save()
|
||||
.then(() => {
|
||||
res.status(200).send("Account added successfully");
|
||||
})
|
||||
.catch(() => {
|
||||
res.status(400).send("Unable to save to database");
|
||||
});
|
||||
}
|
||||
else {
|
||||
res.json(user);
|
||||
console.log("user");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
loginRoute.route('/post').post(function (req, res) {
|
||||
//console.log(req);
|
||||
//console.log(res);
|
||||
var username = req.body.user;
|
||||
var password = req.body.pass;
|
||||
console.log(username);
|
||||
console.log(password);
|
||||
LInfo.findOne({user: username, pass: password},
|
||||
function(err, user){
|
||||
if(err){
|
||||
res.json(err);
|
||||
console.log(user);
|
||||
if(!user){
|
||||
res.json(null);
|
||||
console.log("err");
|
||||
}
|
||||
else {
|
||||
res.json(user);
|
||||
console.log("user");
|
||||
}
|
||||
});
|
||||
});
|
||||
module.exports = loginRoute;
|
||||
@@ -5,6 +5,7 @@ const PORT = 4000;
|
||||
const cors = require('cors');
|
||||
const mongoose = require('mongoose');
|
||||
const config = require('./DB.js');
|
||||
const loginRoute = require('./login.route');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.connect(config.DB, { useNewUrlParser: true }).then(
|
||||
@@ -16,6 +17,8 @@ app.use(cors());
|
||||
app.use(bodyParser.urlencoded({extended: true}));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.use('/login', loginRoute);
|
||||
|
||||
app.listen(PORT, function(){
|
||||
console.log('Server is running on Port:',PORT);
|
||||
});
|
||||
@@ -1,17 +1,15 @@
|
||||
const mongoose = require('mongoose');
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
let LInfo = new Schema({
|
||||
username: { type: String, unique: true, required: true },
|
||||
hash: { type: String, required: true },
|
||||
firstName: { type: String, required: true },
|
||||
lastName: { type: String, required: true },
|
||||
user: { type: String, unique: true, required: true },
|
||||
pass: { type: String, required: true },
|
||||
firstName: { type: String, required: false },
|
||||
lastName: { type: String, required: false },
|
||||
createdDate: { type: Date, default: Date.now }
|
||||
},{
|
||||
collection: 'users'
|
||||
collection: 'users1'
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
schema.set('toJSON', {virtuals: true});
|
||||
|
||||
module.exports = mongoose.model('User', schema);
|
||||
module.exports = mongoose.model('User', LInfo);
|
||||
0
attendancetracker/src/components/Account.vue
Normal file
0
attendancetracker/src/components/Account.vue
Normal file
0
attendancetracker/src/components/Calendar.vue
Normal file
0
attendancetracker/src/components/Calendar.vue
Normal file
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="hello">
|
||||
<h1>Johnny is horribl</h1>
|
||||
<p>
|
||||
For a guid:e and recipes on how to configure / customize this project,<br>
|
||||
check out the
|
||||
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||
</p>
|
||||
<h3>Installed CLI Plugins</h3>
|
||||
<ul>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
|
||||
</ul>
|
||||
<h3>Essential Links</h3>
|
||||
<ul>
|
||||
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||
</ul>
|
||||
<h3>Ecosystem</h3>
|
||||
<ul>
|
||||
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'HelloWorld',
|
||||
props: {
|
||||
msg: String
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||
<style scoped>
|
||||
h3 {
|
||||
margin: 40px 0 0;
|
||||
}
|
||||
ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
li {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
}
|
||||
a {
|
||||
color: #42b983;
|
||||
}
|
||||
</style>
|
||||
@@ -1,60 +0,0 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="buttons">
|
||||
<b-button v-b-modal.add-modal>Add Calendar Event</b-button>
|
||||
</div>
|
||||
<full-calendar :events="events" @event-selected="openEditModal" defaultView="month" />
|
||||
<b-modal id="add-modal" title="Add Calendar Event" hide-footer ref="add-modal">
|
||||
<CalendarForm :edit="false" @eventSaved="closeModal()" />
|
||||
</b-modal>
|
||||
<b-modal id="edit-modal" title="Edit Calendar Event" hide-footer ref="edit-modal">
|
||||
<CalendarForm :edit="true" :calendarEvent="calendarEvent" @eventSaved="closeModal()" />
|
||||
</b-modal>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
// @ is an alias to /src
|
||||
import CalendarForm from "@/components/CalendarForm.vue";
|
||||
import { requestsMixin } from "../mixins/requestsMixin";
|
||||
export default {
|
||||
name: "home",
|
||||
components: {
|
||||
CalendarForm
|
||||
},
|
||||
mixins: [requestsMixin],
|
||||
computed: {
|
||||
events() {
|
||||
return this.$store.state.events;
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
calendarEvent: {}
|
||||
};
|
||||
},
|
||||
async beforeMount() {
|
||||
await this.getEvents();
|
||||
},
|
||||
methods: {
|
||||
async getEvents() {
|
||||
const response = await this.getCalendar();
|
||||
this.$store.commit("setEvents", response.data);
|
||||
},
|
||||
closeModal() {
|
||||
this.$refs["add-modal"].hide();
|
||||
this.$refs["edit-modal"].hide();
|
||||
this.calendarEvent = {};
|
||||
},
|
||||
openEditModal(event) {
|
||||
let { id, start, end, title } = event;
|
||||
this.calendarEvent = { id, start, end, title };
|
||||
this.$refs["edit-modal"].show();
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.buttons {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,24 +1,26 @@
|
||||
<template>
|
||||
<form @submit.prevent="add">
|
||||
<div class="login">
|
||||
<h1 class="title">Login</h1>
|
||||
<div class="field">
|
||||
<label class="label">Username</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" placeholder="e.g Alex Smith" name="username">
|
||||
<input type="text" class="form-control" v-model="post.user">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">Password</label>
|
||||
<div class="control">
|
||||
<input class="input" type="password" placeholder="e.g. alexsmith@gmail.com" name="password">
|
||||
<input type="password" class="form-control" v-model="post.pass">
|
||||
</div>
|
||||
</div>
|
||||
<div class="login-button">
|
||||
<div class="control">
|
||||
<button @click="add()">Click Me</button>
|
||||
<button>Click Me</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
@@ -31,22 +33,26 @@
|
||||
|
||||
<script>
|
||||
export default {
|
||||
|
||||
methods: {
|
||||
data() {
|
||||
data() {
|
||||
return {
|
||||
post: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add(){
|
||||
let uri = 'http://localhost:4000/login/post';
|
||||
this.axios.post(uri, this.post).then(() => {
|
||||
this.$router.push({username: 'username'});
|
||||
this.$router.push({password: 'password'});
|
||||
let uri = 'http://65.92.152.100:4000/login/post';
|
||||
this.axios.post(uri, this.post).then(res => {
|
||||
if(!res.data){
|
||||
alert("Incorrect Username/Password");
|
||||
}else{
|
||||
this.$router.push({name: 'account'});
|
||||
console.log(res.data);
|
||||
alert("Username: " + res.data.user);
|
||||
alert("Password: " + res.data.pass);
|
||||
document.cookie = "user="+res.data.user;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
55
attendancetracker/src/components/Register.vue
Normal file
55
attendancetracker/src/components/Register.vue
Normal file
@@ -0,0 +1,55 @@
|
||||
<template>
|
||||
<form @submit.prevent="add">
|
||||
<div class="login">
|
||||
<h1 class="title">Register</h1>
|
||||
<div class="field">
|
||||
<label class="label">Username</label>
|
||||
<div class="control">
|
||||
<input type="text" class="form-control" v-model="post.user">
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">Password</label>
|
||||
<div class="control">
|
||||
<input type="password" class="form-control" v-model="post.pass">
|
||||
</div>
|
||||
</div>
|
||||
<div class="login-button">
|
||||
<div class="control">
|
||||
<button>Click Me</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.field {
|
||||
width: 50%;
|
||||
font-family:
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
post: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add(){
|
||||
let uri = 'http://65.92.152.100:4000/login/add';
|
||||
this.axios.post(uri, this.post).then(res => {
|
||||
if(!res.data.user){
|
||||
alert("Success! Account Created!");
|
||||
this.$router.push({name: ''});
|
||||
}else{
|
||||
alert("That Username Already Exists!");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -20,25 +20,24 @@ import axios from 'axios';
|
||||
Vue.use(VueAxios, axios);
|
||||
Vue.config.productionTip = false;
|
||||
|
||||
import HelloWorld from './components/HelloWorld.vue';
|
||||
import Login from './components/Login.vue';
|
||||
import Home from './components/Home.vue';
|
||||
|
||||
import Calendar from './components/Calendar.vue';
|
||||
import Register from './components/Register.vue';
|
||||
const routes = [
|
||||
{
|
||||
name: 'home',
|
||||
path: '/',
|
||||
component: HelloWorld
|
||||
},
|
||||
{
|
||||
name: 'login',
|
||||
path: '/login',
|
||||
path: '/',
|
||||
component: Login
|
||||
},
|
||||
{
|
||||
name: 'calendar',
|
||||
path: '/calendar',
|
||||
component: Home
|
||||
component: Calendar
|
||||
},
|
||||
{
|
||||
name: 'Register',
|
||||
path: '/register',
|
||||
component: Register
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
const APIURL = "http://localhost:3000";
|
||||
const axios = require("axios");
|
||||
export const requestsMixin = {
|
||||
methods: {
|
||||
getCalendar() {
|
||||
return axios.get(`${APIURL}/calendar`);
|
||||
},
|
||||
addCalendar(data) {
|
||||
return axios.post(`${APIURL}/calendar`, data);
|
||||
},
|
||||
editCalendar(data) {
|
||||
return axios.put(`${APIURL}/calendar/${data.id}`, data);
|
||||
},
|
||||
deleteCalendar(id) {
|
||||
return axios.delete(`${APIURL}/calendar/${id}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user