Skip to content
Snippets Groups Projects
Commit b995a1cb authored by GustafWallstrom's avatar GustafWallstrom
Browse files

Some rules for what new posts should contain

parent 04208431
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@
</div>
<div class="form-group">
<label for="exampleInputPassword1">Number of throws</label>
<textarea name="description" [(ngModel)]="post.description" class="form-control" id="exampleInputPassword1" placeholder="Throws">
<textarea name="description" [(ngModel)]="post.description" class="form-control" id="exampleInputPassword1" placeholder="Number of throws">
</textarea>
</div>
......
......@@ -20,13 +20,13 @@ export class AddPostComponent {
}
addPost() {
if(this.post.title && this.post.description){
if(this.post.title && this.post.description && /^\d+$/.test(this.post.description)){
this.addPostService.addPost(this.post).subscribe(res =>{
this.closeBtn.nativeElement.click();
this.commonService.notifyPostAddition();
});
} else {
alert('Enter course and number of strokes!');
alert('Enter course and number of strokes!\nMake sure number of throws only contains digits.');
}
}
......
......@@ -4,10 +4,5 @@
<input name="email" [(ngModel)] = "user.username" type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input name="password" [(ngModel)] = "user.password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" (click)="validateLogin();" type="button">Sign in</button>
</form>
\ No newline at end of file
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { User } from '../models/user.model';
import { LOCAL_STORAGE, StorageService } from 'ngx-webstorage-service';
@Injectable()
export class LoginService {
......
......@@ -13,6 +13,7 @@ app.use(bodyParser.urlencoded({
}))
app.post('/api/user/login', (req, res) => {
mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
......@@ -24,6 +25,8 @@ app.post('/api/user/login', (req, res) => {
}, function (err, user) {
if (err) throw err;
if (user.length === 1) {
//let key = 'currentUser';
//localStorage.setItem(key, stringify(user.body.name));
return res.status(200).json({
status: 'success',
data: user
......@@ -45,8 +48,7 @@ app.post('/api/user/create', (req, res) => {
const user = new User({
name: req.body.name,
username: req.body.username,
password: req.body.password,
date: req.body.date
password: req.body.password
})
user.save((err, res) => {
if (err) throw err;
......@@ -66,6 +68,7 @@ app.post('/api/post/createPost', (req, res) => {
if (err) throw err;
const post = new Post({
title: req.body.title,
//title: localStorage.getItem(currentUser),
description: req.body.description,
date: req.body.date
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment