Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1c20782

Browse files
changes
1 parent 67b8cbe commit 1c20782

File tree

4 files changed

+81
-50
lines changed

4 files changed

+81
-50
lines changed

‎api/server.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,32 @@ var port = process.env.PORT || 3003;
2121
var router = express.Router();
2222

2323
app.use(express.static(path.join(__dirname, 'dist')))
24+
app.use(function(req, res, next) {
25+
res.header("Access-Control-Allow-Origin", "*");
26+
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
27+
next();
28+
});
2429

2530
router.route('/register/')
2631
.post(function(req, res) {
32+
console.log(req.body)
2733
var login = new Login();
2834
Login.findOne({"username": req.body.username}, function(err, user_data){
29-
if(user_data)
35+
if(err){
36+
console.log(err)
37+
}
38+
if(user_data){
3039
return res.json({
3140
status : 409,
3241
message : "User already exist"
3342
});
43+
}
44+
console.log(req.body, 44)
3445
login.username = req.body.username;
3546
login.password = req.body.password;
3647
login.confirm_password = req.body.confirm_password;
3748
login.email = req.body.email;
49+
console.log(login ,49)
3850
login.save(function(err, login_data){
3951
if(err)
4052
return res.status(400).send(err);
@@ -50,7 +62,7 @@ router.route('/login')
5062
.post(function(req, res){
5163
Login.findOne({"username": req.body.username, "password": req.body.password}, function(err, user_data){
5264
if(err || !user_data){
53-
return res.json({
65+
return res.status(401).json({
5466
status : 401,
5567
message : "Invalid username and password.",
5668
});

‎src/components/HelloWorld.vue

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h1 style="text-align:center; margin-bottom:20px">Login</h1>
66
<b-form-group id="exampleInputGroup1">
77
<b-form-input id="exampleInput1"
8-
type="text" v-model="form.name" required
8+
type="text" v-model="form.username" required
99
placeholder="Username"
1010
></b-form-input>
1111
</b-form-group>
@@ -20,7 +20,7 @@
2020
<b-form-checkbox v-model="form.checked" id="exampleInput4">
2121
Check me out
2222
</b-form-checkbox>
23-
<router-link to="signup" style="float:right">Dont have an account?</router-link>
23+
<router-link to="signup" style="float:right">signup?</router-link>
2424
</b-form-group>
2525
<b-button type="submit" variant="primary" style="width:50%">Submit</b-button>
2626
<b-button type="reset" variant="secondary" style="width:48%">Reset</b-button>
@@ -33,45 +33,39 @@ import axios from 'axios';
3333
export default {
3434
data () {
3535
return {
36-
form: [
37-
{
38-
username:'',
39-
password:''
40-
}
41-
]
42-
36+
form: {
37+
username: '',
38+
password: '',
39+
},
4340
}
4441
},
45-
created() {
46-
axios.get(`http://localhost:3001/api/login`)
42+
methods: {
43+
onSubmit (evt) {
44+
evt.preventDefault()
45+
// this.$router.push('/home')
46+
axios.post(`http://localhost:3003/api/login`, this.form)
4747
.then(response => {
4848
// JSON responses are automatically parsed.
49-
this.login = response.data
49+
this.form = response.data
50+
sessionStorage.setItem('token',response.data.token);
51+
this.$router.push('/home')
5052
})
5153
.catch(e => {
5254
console.log(e)
5355
})
54-
55-
56-
},
57-
methods: {
58-
onSubmit (evt) {
59-
evt.preventDefault()
60-
this.$router.push('/home')
6156
}
6257
}
6358
}
6459
</script>
6560

66-
<!-- Add "scoped" attribute to limit CSS to this component only -->
6761
<style scoped>
6862
h1, h2 {
6963
font-weight: normal;
7064
}
7165
ul {
7266
list-style-type: none;
7367
padding: 0;
74-
}
68+
}
7569
li {
7670
display: inline-block;
7771
margin: 0 10px;
@@ -83,10 +77,6 @@ a{
8377
width: 400px;
8478
8579
}
86-
.main{
87-
background-color:red
88-
}
89-
body{
90-
background-color:
91-
}
80+
81+
9282
</style>

‎src/components/Signup.vue

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h1 style="text-align:center; margin-bottom:20px">Signup</h1>
55
<b-form-group id="exampleInputGroup1">
66
<b-form-input id="exampleInput1"
7-
type="text" v-model="form.name" required
7+
type="text" v-model="form.username" required
88
placeholder="Name"
99
></b-form-input>
1010
</b-form-group>
@@ -22,15 +22,30 @@
2222
placeholder="Password"
2323
></b-form-input>
2424
</b-form-group>
25+
<b-form-group id="exampleInputGroup2" >
26+
<b-form-input id="exampleInput2"
27+
type="password" v-model="form.confirm_password" required
28+
placeholder="Confirm_Password"
29+
></b-form-input>
30+
</b-form-group>
2531

2632

2733
<b-form-group id="exampleGroup4">
2834
<b-form-checkbox v-model="form.checked" id="exampleInput4">
2935
Check me out
3036
</b-form-checkbox>
37+
<a style="float:right" href="/">login?</a>
3138
</b-form-group>
32-
<b-button type="submit" variant="primary" style="width:50%">Submit</b-button>
33-
<b-button type="reset" variant="secondary" style="width:48%">Reset</b-button>
39+
40+
<b-button type="submit" variant="primary" style="width:100%">Submit</b-button>
41+
<b-modal id="modalsm" style="text-align:center" ref="modal" size="sm" hide-footer>
42+
<div style="color:#28a745; font-size:20px">
43+
<b>Register Successfully!</b>
44+
</div>
45+
<b-btn class="mt-3" variant="outline-success" style="float:right" @click="onClick">Login</b-btn>
46+
</b-modal>
47+
48+
3449
</b-form>
3550
</div>
3651
</template>
@@ -43,17 +58,37 @@ export default {
4358
return {
4459
form: {
4560
email: '',
46-
name: '',
47-
password: ''
61+
username: '',
62+
password: '',
63+
confirm_password:''
4864
},
49-
foods: [
50-
{ text: 'Select One', value: null },
51-
'Carrots', 'Beans', 'Tomatoes', 'Corn'
52-
]
65+
5366
}
5467
},
55-
created() {
56-
axios.get(`/api/register`)
68+
69+
methods: {
70+
onSubmit (evt) {
71+
evt.preventDefault()
72+
axios.post(`http://localhost:3003/api/register`, this.form)
73+
.then(response => {
74+
// JSON responses are automatically parsed.
75+
this.form = response.data;
76+
if(this.form.status === 200)
77+
this.$refs.modal.show()
78+
})
79+
.catch(e => {
80+
console.log(e)
81+
})
82+
},
83+
onClick(e){
84+
e.preventDefault();
85+
this.$router.push('/')
86+
}
87+
}
88+
/*created(evt) {
89+
console.log(evt)
90+
evt.preventDefault()
91+
axios.post(`http://localhost:3003/api/register`, this.form)
5792
.then(response => {
5893
// JSON responses are automatically parsed.
5994
this.form = response.data
@@ -63,22 +98,16 @@ export default {
6398
})
6499
65100
66-
},
67-
methods: {
68-
onSubmit (evt) {
69-
evt.preventDefault()
70-
this.$router.push('/home')
71-
}
72-
}
101+
},*/
73102
}
74103
</script>
75104

76105

77106
<style scoped>
78107
79108
80-
a{
81-
color: #42b983;
109+
a{
110+
text-decoration:none;
82111
}
83112
.container{
84113
width: 400px;

‎src/components/home.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<div>
33
<h1 style="text-align:center; margin-top:200px; font-size:100px"><b>Hello there!</b></h1>
44
</div>
5-
</template>
5+
</template>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /