Skip to content

Instantly share code, notes, and snippets.

@mike1477
mike1477 / change-password.component.ts
Created October 18, 2019 17:35
Video 38 | Using Angular ngx-alerts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { AuthService } from 'src/app/shared/services/auth.service';
import { ProgressBarService } from 'src/app/shared/services/progress-bar.service';
import { AlertService } from 'ngx-alerts';
@Component({
selector: 'app-change-password',
templateUrl: './change-password.component.html',
styleUrls: ['./change-password.component.scss']
@mike1477
mike1477 / change-password.component.ts
Created October 17, 2019 14:41
Video 37 | Use Angular ngx-progressbar/core
changePassword() {
this.progressBar.startLoading();
this.authService.changePassword(this.model).subscribe(() => {
this.progressBar.setSuccess();
console.log("success");
this.progressBar.completeLoading();
}, error => {
this.progressBar.setError();
console.log(error);
this.progressBar.completeLoading();
@mike1477
mike1477 / auth.service.ts
Created October 14, 2019 17:13
Video 33 | Create register method in Angular service
import { HttpClient, HttpHeaders } from '@angular/common/http';
// Inside class
employersUrl = "http://localhost:5000/api/employers/";
confirmEmailUrl = "test.com";
// Method
register(model: any) {
@mike1477
mike1477 / login.component.ts
Created October 13, 2019 17:00
Video 32 | Injecting service into component
import { AuthService } from 'src/app/shared/services/auth.service';
constructor(private authService: AuthService) { }
onSubmit(f: NgForm) {
const loginObserver = {
next: x => console.log('User logged in'),
@mike1477
mike1477 / AuthController.cs
Created October 12, 2019 15:30
Video 31 | Create Angular Service
return Ok(new
{
result = result,
token = JwtTokenGeneratorMachine(user).Result
});
@mike1477
mike1477 / .ts
Last active October 10, 2019 17:36
Video 30 | Use Template Driven Forms in Angular
onSubmit(f: NgForm) {
console.log(f.value); // { first: '', last: '' }
console.log(f.valid); // false
}
@mike1477
mike1477 / login.component.html
Created October 9, 2019 17:06
Video 29 | Create Bootstrap forms
<div class="row">
<div class="col-md-6 offset-md-3 mt-4">
<h3>Login</h3>
<form>
<div class="form-group">
<label for="loginUsername">Username</label>
<input type="text"
class="form-control"
id="loginUsername"
placeholder="Enter username">
@mike1477
mike1477 / header.component.html
Created October 8, 2019 15:21
Video 28 | Create auth module and login, register and reset password components
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link"
href="#">Register</a>
[routerLink]="['register']"
routerLinkActive="active">Register</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="#">Login</a>
@mike1477
mike1477 / AuthController.cs
Created October 4, 2019 22:11
Video 25 | Use Identity to change password
// Post api/auth/resetpassword
[HttpPost("resetpassword")]
public async Task<IActionResult> ResetPassword(ResetPasswordViewModel model)
{
var user = await _userManager.FindByEmailAsync(model.Email);
if (user != null || user.EmailConfirmed)
{
//Send Email
var token = await _userManager.GeneratePasswordResetTokenAsync(user);
var changePasswordUrl = Request.Headers["changePasswordUrl"];//http://localhost:4200/change-password
@mike1477
mike1477 / AuthController.cs
Created September 27, 2019 19:05
Video 24 | Use Identity management to confirm email
// Post api/auth/confirmemail
[HttpPost("confirmemail")]
public async Task<IActionResult> ConfirmEmail(ConfirmEmailViewModel model)
{
var employer = await _userManager.FindByIdAsync(model.UserId);
var confirm = await _userManager.ConfirmEmailAsync(employer, Uri.UnescapeDataString(model.Token));
if (confirm.Succeeded)
{
return Ok();