Commit 6974cdf7 authored by Marcelo Rivera's avatar Marcelo Rivera

(feat): auto-subscribe on login or signup when on pro standalone

1 merge request!528WIP: (feat): Minds Pro
Pipeline #82521617 failed with stages
in 6 minutes and 8 seconds
import { Component, EventEmitter, NgZone } from '@angular/core';
import { Component, EventEmitter, Input, NgZone, Output } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Client } from '../../../services/api';
import { Session } from '../../../services/session';
import { MindsUser } from '../../../interfaces/entities';
@Component({
moduleId: module.id,
selector: 'minds-form-login',
outputs: ['done', 'doneRegistered'],
templateUrl: 'login.html',
})
export class LoginForm {
@Input() autoSubscribe: MindsUser;
@Output() done: EventEmitter<any> = new EventEmitter();
@Output() doneRegistered: EventEmitter<any> = new EventEmitter();
errorMessage: string = '';
twofactorToken: string = '';
hideLogin: boolean = false;
......@@ -20,9 +25,6 @@ export class LoginForm {
form: FormGroup;
done: EventEmitter<any> = new EventEmitter();
doneRegistered: EventEmitter<any> = new EventEmitter();
//Taken from advice in https://stackoverflow.com/a/1373724
private emailRegex: RegExp = new RegExp(
"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"
......@@ -54,11 +56,18 @@ export class LoginForm {
this.errorMessage = '';
this.inProgress = true;
let opts = {
username: username,
password: this.form.value.password,
};
if (this.autoSubscribe) {
opts['from'] = this.autoSubscribe.guid;
}
this.client
.post('api/v1/authenticate', {
username: username,
password: this.form.value.password,
})
.post('api/v1/authenticate', opts)
.then((data: any) => {
// TODO: [emi/sprint/bison] Find a way to reset controls. Old implementation throws Exception;
this.inProgress = false;
......
......@@ -12,6 +12,7 @@ import { Client } from '../../../services/api';
import { Session } from '../../../services/session';
import { ReCaptchaComponent } from '../../../modules/captcha/recaptcha/recaptcha.component';
import { ExperimentsService } from '../../experiments/experiments.service';
import { MindsUser } from '../../../interfaces/entities';
@Component({
moduleId: module.id,
......@@ -19,11 +20,15 @@ import { ExperimentsService } from '../../experiments/experiments.service';
templateUrl: 'register.html',
})
export class RegisterForm {
@Input() referrer: string;
@Input() autoSubscribe: MindsUser;
@Output() done: EventEmitter<any> = new EventEmitter();
errorMessage: string = '';
twofactorToken: string = '';
hideLogin: boolean = false;
inProgress: boolean = false;
@Input() referrer: string;
captcha: string;
takenUsername: boolean = false;
usernameValidationTimeout: any;
......@@ -34,8 +39,6 @@ export class RegisterForm {
fbForm: FormGroup;
minds = window.Minds;
@Output() done: EventEmitter<any> = new EventEmitter();
@ViewChild('reCaptcha', { static: false }) reCaptcha: ReCaptchaComponent;
constructor(
......@@ -87,8 +90,15 @@ export class RegisterForm {
this.form.value.referrer = this.referrer;
this.inProgress = true;
let opts = { ...this.form.value };
if (this.autoSubscribe) {
opts['from'] = this.autoSubscribe.guid;
}
this.client
.post('api/v1/register', this.form.value)
.post('api/v1/register', opts)
.then((data: any) => {
// TODO: [emi/sprint/bison] Find a way to reset controls. Old implementation throws Exception;
......
......@@ -11,7 +11,10 @@
<a (click)="currentSection = 'register'">Start a Minds channel</a>
</span>
<minds-form-login (done)="registered()"></minds-form-login>
<minds-form-login
[autoSubscribe]="autoSubscribe"
(done)="registered()"
></minds-form-login>
</ng-container>
<ng-container *ngIf="currentSection === 'register'">
......@@ -21,7 +24,10 @@
</a>
</span>
<minds-form-register (done)="registered()"></minds-form-register>
<minds-form-register
[autoSubscribe]="autoSubscribe"
(done)="registered()"
></minds-form-register>
</ng-container>
</div>
</div>
......
......@@ -21,6 +21,10 @@ export class ProChannelLoginComponent {
return this.service.currentChannel.pro_settings;
}
get autoSubscribe() {
return window.Minds.pro ? this.service.currentChannel : null;
}
constructor(
public session: Session,
public service: ProChannelService,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment