Skip to content

Instantly share code, notes, and snippets.

View xavidram's full-sized avatar

Xavid Ramirez xavidram

View GitHub Profile
@xavidram
xavidram / create-pfx
Created September 11, 2022 13:23 — forked from jamielaundon/create-pfx
Create IIS .pfx from Let's Encrypt fullchain and privkey
sudo openssl pkcs12 -export -in /etc/letsencrypt/live/domain.com/fullchain.pem -inkey /etc/letsencrypt/live/domain.com/privkey.pem -out domain.com.pfx
Verifying my Blockstack ID is secured with the address 1NPnrfmQHVDmDTKpDnNzhkPyPH6ZxSnyhj https://explorer.blockstack.org/address/1NPnrfmQHVDmDTKpDnNzhkPyPH6ZxSnyhj
:host {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.form-container {
height: 300px;
width: 350px;
}
const routes: Routes = [
// Home Page Route path ''
{
path: '',
component: HomePageComponent,
canActivate: [AuthGuard]
},
// Login Page route path /login
{
path: 'login',
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
// Check if a 'currentUser' exists in the localStorage object
// this will return undefined || false if there isn't
if (localStorage['currentUsr']) {
// User is logged in, let's let them through
return true;
} else {
// user is not logged in, let's route them to the login page.
login() {
// We checked for validation in HTML so our credentials should not be blank.
this.auth.login(this.credentials.email, this.credentials.pwd).subscribe((data) => {
if (data.message === false) {
// if invalid login, reset the form
this.credentials.email = '';
this.credentials.pwd = '';
} else {
// if we get here, there is no error, the return is valid
// Let's first save the info into local storage for later use. We can parse this back
function login(req, res) {
// Find user by email
User.findOne({
email: req.body.email
}).then(user => {
// Once we find the user, now let's pass the password from req.body to authenticate
if (!user) {
// Return false, user not even registered, but let's not tell them.
res.send({
message: false
/**
* Authenticate - check if the passwords are the same
*
* @param {String} password
* @param {Function} callback
* @return {Boolean}
* @api public
*/
authenticate(password, callback) {
if (!callback) {
<div class="form-container">
<form name="form" class="loginForm" (ngSubmit)="f.form.valid && login()" #f="ngForm" novalidate>
<div class="form-group">
<h2>User Login</h2>
</div>
<div class="form-group">
<label>Email</label>
<input class="form-control" type="email" name="email" [(ngModel)]="credentials.email" required>
</div>
<div class="form-group">
function create(req, res) {
// Define the new user, give the constructor the req.body containing all fields
let newUser = new User(req.body);
// if role not defined, lets give it a default user role, although our model should handle this
newUser.role = 'user';
// Now lets save the user
return newUser.save().then(function(user) { // then when the user saves
// We will be returning only a few fields that we should need.
res.json({
name: user.name,