Skip to content

Commit 366459a

Browse files
committed
form builder adding
1 parent 763e89e commit 366459a

15 files changed

Lines changed: 144 additions & 230 deletions

codecamp-front/src/app/app-routing.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PracticeComponent } from './components/practice/practice.component';
1212
import { DiscussComponent } from './components/discuss/discuss.component';
1313
import { ContestComponent } from './components/contest/contest.component';
1414
import { AboutComponent } from './components/about/about.component';
15+
import { IdeComponent } from './components/ide/ide.component';
1516

1617

1718

@@ -23,8 +24,9 @@ const appRoutes: Routes = [
2324
{path: 'practice' , component: PracticeComponent},
2425
{path: 'contest' , component: ContestComponent},
2526
{path: 'discuss' , component: DiscussComponent},
26-
{path: 'profile' , component: ProfileComponent}
27-
]
27+
{path: 'profile' , component: ProfileComponent},
28+
{path: 'ide', component: IdeComponent}
29+
];
2830

2931
@NgModule({
3032
imports: [RouterModule.forRoot(appRoutes)],

codecamp-front/src/app/app.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import { ContestComponent } from './components/contest/contest.component';
1717
import { AboutComponent } from './components/about/about.component';
1818

1919
import { AuthService } from './services/auth.service';
20-
import { ValidateService } from './services/validate.service';
2120
import { HttpModule } from '@angular/http';
21+
import { IdeComponent } from './components/ide/ide.component';
2222

2323

2424
@NgModule({
@@ -32,15 +32,16 @@ import { HttpModule } from '@angular/http';
3232
PracticeComponent,
3333
DiscussComponent,
3434
ContestComponent,
35-
AboutComponent
35+
AboutComponent,
36+
IdeComponent
3637
],
3738
imports: [
3839
BrowserModule,
3940
HttpModule,
4041
ReactiveFormsModule,
4142
AppRoutingModule
4243
],
43-
providers: [ValidateService, AuthService],
44+
providers: [ AuthService],
4445
bootstrap: [AppComponent]
4546
})
4647
export class AppModule { }

codecamp-front/src/app/components/ide/ide.component.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
input[type="file"] {
1010
display: none;
11-
}
11+
}

codecamp-front/src/app/components/ide/ide.component.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="container">
22
<div class="row">
33
<div class="col-md-12">
4-
<p>Online IDE</p>
5-
<textarea name="" id="" cols="100" rows="28" ></textarea>
4+
<h1 class="display-4">Online IDE</h1>
5+
<textarea name="" id="" cols="105" rows="28" ></textarea>
66
<div class="row">
77
<div class="col-md-8">
88
<label class="file-upload">Upload File
@@ -11,9 +11,14 @@
1111
</div>
1212
<div class="col-md-4">
1313
<div class="form-check mr-auto">
14-
<input type="checkbox" class="form-check-input" id="exampleCheck1">
15-
<label class="form-check-label" for="exampleCheck1">Check me out</label>
1614
<button class="btn btn-dark">Compile</button>
15+
<div class="form-check">
16+
<input class="form-check-input" type="checkbox" id="gridCheck">
17+
<label class="form-check-label" for="gridCheck">
18+
Check me out
19+
</label>
20+
</div>
21+
1722
</div>
1823
</div>
1924
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<div class="container">
2+
<div class="row show-hide-message">
3+
<div [ngClass]="messageClass">
4+
{{ message }}
5+
</div>
6+
</div>
7+
8+
<form [formGroup]="form" (submit)="onSignupSubmit()">
9+
<div class="form-group">
10+
<label for="username">Username</label>
11+
<input type="text"
12+
name="username"
13+
formControlName="username"
14+
class="form-control"
15+
placeholder="Enter username(XYZ)"
16+
autocomplete="off"
17+
[ngClass]="{'is-invalid': (form.controls.username.errors && form.controls.username.dirty) , 'is-valid': !form.controls.username.errors}">
18+
</div>
19+
20+
<!-- Email Input -->
21+
<div class="form-group">
22+
<label for="password">Password</label>
23+
<input type="password"
24+
name="password"
25+
formControlName="password"
26+
class="form-control"
27+
placeholder="Enter password"
28+
autocomplete="off"
29+
[ngClass]="{'is-invalid': (form.controls.password.errors && form.controls.password.dirty) , 'is-valid': !form.controls.password.errors}">
30+
</div>
31+
32+
<input
33+
[disabled]="!form.valid"
34+
type="submit" class="btn btn-primary" value="Sign up">
35+
</form>
36+
</div>

codecamp-front/src/app/components/login/login.component.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,4 @@ export class LoginComponent implements OnInit {
1818
ngOnInit() {
1919
}
2020

21-
onLoginSubmit(){
22-
const user = {
23-
username: this.username,
24-
password: this.password
25-
}
26-
this.authService.authenticateUser( user ).subscribe(data => {
27-
if (data.success) {
28-
this.authService.storeUserData(data.token, data.user);
29-
alert('login success');
30-
this.router.navigate(['']);
31-
} else {
32-
this.router.navigate(['/login']);
33-
}
34-
} )
35-
}
3621
}

codecamp-front/src/app/components/navbar/navbar.component.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,5 @@ export class NavbarComponent implements OnInit {
1616

1717
ngOnInit() {
1818
}
19-
onLogoutClick() {
20-
this.authService.logout();
21-
this.router.navigate(['/login']);
22-
return false;
23-
}
19+
2420
}

codecamp-front/src/app/components/profile/profile.component.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ export class ProfileComponent implements OnInit {
1616
) { }
1717

1818
ngOnInit() {
19-
this.authService.getProfile().subscribe(profile =>{
20-
this.user = profile.user;
21-
},
22-
err =>{
23-
console.log(err);
24-
return false;
25-
});
2619
}
2720

2821
}

codecamp-front/src/app/components/register/register.component.html

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<h2 class="display-4">
2-
Register
3-
</h2>
4-
<div class="container">
1+
<div class="container">
2+
<div class="row show-hide-message">
3+
<div [ngClass]="messageClass">
4+
{{ message }}
5+
</div>
6+
</div>
7+
58
<form [formGroup]="form" (submit)="onSignupSubmit()">
69
<div class="form-group">
710
<label for="name">Name</label>
@@ -29,17 +32,16 @@ <h2 class="display-4">
2932
<div class="form-group">
3033
<label for="email">Email</label>
3134
<input type="text"
32-
name="email"
35+
name="email_id"
3336
class="form-control"
34-
[ngClass]="{'is-invalid': (form.controls.email.errors && form.controls.email.dirty) , 'is-valid': !form.controls.email.errors}"
37+
[ngClass]="{'is-invalid': (form.controls.email_id.errors && form.controls.email_id.dirty) , 'is-valid': !form.controls.email_id.errors}"
3538
autocomplete="off"
36-
placeholder="*Email"
37-
formControlName="email"
38-
(blur)="checkEmail()">
39+
placeholder="*email"
40+
formControlName="email_id">
3941
<!-- Validation -->
40-
<div *ngIf="form.controls.email.errors?.required && form.controls.email.dirty" class="invalid-feedback">This Field is required</div>
41-
<div class="invalid-feedback" *ngIf="(form.controls.email.errors?.minlength && form.controls.email.dirty || form.controls.email.errors?.maxlength && form.controls.email.dirty ) && form.controls.email.dirty">Minimum characters: 5, Maximum characters: 30</div>
42-
<div class="invalid-feedback" *ngIf="form.controls.email.errors?.validateEmail && form.controls.email.dirty">This must be a valid e-mail</div>
42+
<div *ngIf="form.controls.email_id.errors?.required && form.controls.email_id.dirty" class="invalid-feedback">This Field is required</div>
43+
<div class="invalid-feedback" *ngIf="(form.controls.email_id.errors?.minlength && form.controls.email_id.dirty || form.controls.email_id.errors?.maxlength && form.controls.email_id.dirty ) && form.controls.email_id.dirty">Minimum characters: 5, Maximum characters: 30</div>
44+
<div class="invalid-feedback" *ngIf="form.controls.email_id.errors?.validateemail && form.controls.email_id.dirty">This must be a valid e-mail</div>
4345
</div>
4446

4547
<div class="form-group">
@@ -55,29 +57,59 @@ <h2 class="display-4">
5557

5658
<div class="form-group">
5759
<label for="city">City</label>
58-
<input type="text" name="city" formControlName="city" class="form-control" placeholder="Enter city" autocomplete="off">
60+
<input type="text"
61+
name="city"
62+
formControlName="city"
63+
class="form-control" placeholder="Enter city" autocomplete="off">
5964
</div>
6065

6166
<div class="form-group">
6267
<label for="dob">Date Of Birth</label>
63-
<input type="date" name="dob" formControlName="dob" class="form-control" autocomplete="off">
68+
<input type="date"
69+
name="dob"
70+
formControlName="dob"
71+
class="form-control"
72+
autocomplete="off"
73+
[ngClass]="{'is-invalid': (form.controls.dob.errors && form.controls.dob.dirty) , 'is-valid': !form.controls.dob.errors}">
6474
</div>
6575

6676
<div class="form-group">
6777
<label for="gender">Gender</label>
68-
<input type="text" name="gender" formControlName="gender" class="form-control" placeholder="Male/Female" autocomplete="off">
78+
<input type="text"
79+
name="gender"
80+
formControlName="gender"
81+
class="form-control"
82+
placeholder="Male/Female"
83+
autocomplete="off">
6984
</div>
7085

7186
<div class="form-group">
7287
<label for="password">Password</label>
73-
<input type="password" name="password" formControlName="password" class="form-control" placeholder="Enter password" autocomplete="off">
88+
<input type="password"
89+
name="password"
90+
formControlName="password"
91+
class="form-control"
92+
placeholder="Enter password"
93+
autocomplete="off"
94+
[ngClass]="{'is-invalid': (form.controls.password.errors && form.controls.password.dirty) , 'is-valid': !form.controls.password.errors}">
7495
</div>
7596

7697
<div class="form-group">
7798
<label for="confirmpassword">Confirm Password</label>
78-
<input type="password" name="confirm" formControlName="confirm" class="form-control" placeholder="Confrim password" autocomplete="off">
99+
<input type="password"
100+
name="confirm"
101+
formControlName="confirm"
102+
class="form-control"
103+
placeholder="Confrim password"
104+
autocomplete="off"
105+
[ngClass]="{'is-invalid': (form.controls.confirm.errors && form.controls.confirm.dirty) || (form.errors?.matchingPasswords && form.controls.confirm.dirty) , 'is-valid': !form.controls.confirm.errors && !form.errors?.matchingPasswords}">
106+
<div *ngIf="form.errors?.matchingPasswords && form.controls.confirm.dirty"
107+
class="invalid-feedback">Password do not match</div>
108+
79109
</div>
80110

81-
<input type="submit" class="btn btn-primary" value="Sign up">
111+
<input
112+
[disabled]="!form.valid"
113+
type="submit" class="btn btn-primary" value="Sign up">
82114
</form>
83115
</div>
Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
22
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
3-
import { ValidateService } from '../../services/validate.service';
43
import { AuthService } from '../../services/auth.service';
54
import { Router } from '@angular/router';
65

@@ -12,9 +11,10 @@ import { Router } from '@angular/router';
1211
export class RegisterComponent implements OnInit {
1312

1413
form: FormGroup;
15-
14+
message;
15+
messageClass;
16+
1617
constructor(
17-
private validateService: ValidateService,
1818
private authService: AuthService,
1919
private router: Router,
2020
private formBuilder: FormBuilder
@@ -27,21 +27,24 @@ export class RegisterComponent implements OnInit {
2727

2828
createForm() {
2929
this.form = this.formBuilder.group({
30-
name: '',
31-
email: ['', Validators.compose([
30+
name: ['', Validators.required],
31+
email_id: ['', Validators.compose([
3232
Validators.required, // Field is required
3333
Validators.minLength(5), // Minimum length is 5 characters
3434
Validators.maxLength(30), // Maximum length is 30 characters
3535
this.validateEmail // Custom validation
3636
])],
37-
password: ['', Validators.required],
37+
password: ['', Validators.compose([
38+
Validators.required,
39+
Validators.minLength(8)
40+
])],
3841
username: ['', Validators.required],
3942
confirm: ['', Validators.required],
4043
college: ['', Validators.required],
4144
gender: '',
4245
dob: ['', Validators.required],
4346
city: ['', Validators.required]
44-
});
47+
}, { validator: this.matchingPasswords('password', 'confirm')});
4548
}
4649

4750
validateEmail(controls) {
@@ -51,13 +54,34 @@ export class RegisterComponent implements OnInit {
5154
if (regExp.test(controls.value)) {
5255
return null; // Return as valid email
5356
} else {
54-
return { 'validateEmail': true } // Return as invalid email
57+
return { 'validateEmail': true }; // Return as invalid email
5558
}
5659
}
5760

58-
61+
matchingPasswords(password, confirm) {
62+
return (group: FormGroup) => {
63+
// Check if both fields are the same
64+
if (group.controls[password].value === group.controls[confirm].value) {
65+
return null; // Return as a match
66+
} else {
67+
return { 'matchingPasswords': true }; // Return as error: do not match
68+
}
69+
};
70+
}
5971
onSignupSubmit() {
60-
72+
const user = {
73+
username: this.form.get('username').value,
74+
email_id: this.form.get('email_id').value,
75+
name: this.form.get('name').value,
76+
college: this.form.get('college').value,
77+
password: this.form.get('password').value,
78+
dob: this.form.get('dob').value,
79+
city: this.form.get('city').value,
80+
gender: this.form.get('gender').value
81+
};
82+
this.authService.registerUser(user).subscribe(data => {
83+
console.log(data);
84+
});
85+
this.router.navigate(['/login']);
6186
}
62-
6387
}

0 commit comments

Comments
 (0)