Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homebridge-ring component tweaks #486

Merged
merged 3 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,6 @@ yarn.lock
# dotenv environment variables file
.env
.DS_Store

# webstorm/intellij
.idea
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"concurrently": "^5.0.2",
"dotenv": "^8.2.0",
"lodash": "^4.17.15",
"node-machine-id": "^1.1.12",
"nodemon": "^2.0.2",
"passport": "^0.4.1",
"passport-jwt": "^4.0.0",
Expand All @@ -106,7 +105,6 @@
"tsconfig-paths": "^3.9.0",
"tslint": "^5.20.1",
"typescript": "3.6.4",
"uuid": "^3.4.0",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-node-externals": "^1.7.2"
Expand Down Expand Up @@ -139,4 +137,4 @@
"smart home",
"hb-service"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { Injectable, NotFoundException, BadRequestException, UnauthorizedException, HttpException, InternalServerErrorException } from '@nestjs/common';
import { Injectable, UnauthorizedException, HttpException, InternalServerErrorException } from '@nestjs/common';
import { Logger } from '../../../../core/logger/logger.service';
import { ConfigService } from '../../../../core/config/config.service';
import * as rp from 'request-promise-native';
import { machineId } from 'node-machine-id';
import * as generateRandomUuid from 'uuid/v4';
import * as generateUuidFromNamespace from 'uuid/v5';

@Injectable()
export class HomebridgeRingService {
private uuidNamespace = 'e53ffdc0-e91d-4ce1-bec2-df939d94739c';

constructor(
private configService: ConfigService,
private logger: Logger,
Expand All @@ -33,7 +28,6 @@ export class HomebridgeRingService {
grant_type: 'password',
password: credentials.password,
username: credentials.email,
hardware_id: await this.getHardwareId(),
},
});
} catch (e) {
Expand All @@ -49,18 +43,4 @@ export class HomebridgeRingService {
}
}
}

generateUuid(seed?: string) {
if (seed) {
return generateUuidFromNamespace(seed, this.uuidNamespace);
}

return generateRandomUuid();
}

async getHardwareId() {
const id = await machineId();
return this.generateUuid(id);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ <h5 class="modal-title">Homebridge Ring</h5>
</div>

<div class="modal-body">
<div class="mt-3">
<markdown hrefTargetBlank class="plugin-md" [data]="schema.headerDisplay" *ngIf="schema.headerDisplay">
</markdown>
</div>

<div *ngIf="!pluginConfig?.refreshToken && !(pluginConfig?.email && pluginConfig?.password)">

<div class="d-flex justify-content-center">
Expand All @@ -21,31 +16,36 @@ <h5 class="modal-title">Homebridge Ring</h5>
<h4 class="text-center primary-text mb-3"
translate="plugins.settings.custom.homebridge-gsh.label_link_account"></h4>

<div [hidden]="doingLogin">
<div class="form-group" *ngIf="!twoFactorRequired">
<label for="ringAccountEmail">Ring Account Email</label>
<input formControlName="email" type="email" class="form-control" id="ringAccountEmail"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>
<div class="form-group" *ngIf="!twoFactorRequired">
<label for="ringAccountPassword">Ring Account Password</label>
<input formControlName="password" type="password" class="form-control" id="ringAccountPassword"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<small id="ringAccountPasswordHelp" class="form-text text-muted">
Your password will not be stored or sent to any third parties apart from ring.com.
</small>
</div>
<markdown hrefTargetBlank class="plugin-md" [data]="schema.accountLinkingHeader" *ngIf="schema.accountLinkingHeader">
</markdown>

<div [hidden]="doingLogin" class="card p-3">
<ng-container *ngIf="!twoFactorRequired">
<div class="form-group">
<label for="ringAccountEmail">Ring Account Email</label>
<input formControlName="email" type="email" class="form-control" id="ringAccountEmail"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
</div>
<div class="form-group">
<label for="ringAccountPassword">Ring Account Password</label>
<input formControlName="password" type="password" class="form-control" id="ringAccountPassword"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<small id="ringAccountPasswordHelp" class="form-text text-muted">
Your password will not be stored or sent to any third parties apart from ring.com.
</small>
</div>
</ng-container>
<div class="form-group" *ngIf="twoFactorRequired">
<label for="ringVerificationCode">Verification Code</label>
<input formControlName="twoFactorAuthCode" type="text" class="form-control" id="ringVerificationCode"
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<small id="ringVerificationCodeHelp" class="form-text text-muted">
Please enter the code we sent to {{ phoneLastTwo }}.
Please enter the code sent to phone {{ phoneLastTwo }}
</small>
</div>
<div class="text-center">
<div class="text-danger mb-2" *ngIf="loginFailReason">{{ loginFailReason | titlecase }}</div>
<button type="button" class="btn btn-primary ml-0" (click)="linkAccount()"
<button type="submit" class="btn btn-primary ml-0" (click)="linkAccount()"
[disabled]="linkAccountForm.invalid">
{{ twoFactorRequired ? 'Verify Code' : 'Get Token' }}
</button>
Expand All @@ -63,12 +63,16 @@ <h1>
</div>

<div class="text-center mt-1" *ngIf="pluginConfig?.refreshToken || (pluginConfig?.email && pluginConfig?.password)">
<i class="fas fa-check-circle primary-text" style="font-size:50px;"></i>
<h4 class="mt-2" translate="plugins.settings.custom.homebridge-gsh.label_account_linked">
Account Linked
</h4>
<div class="mt-3" *ngIf="!justLinked">
<markdown hrefTargetBlank class="plugin-md" [data]="schema.headerDisplay" *ngIf="schema.headerDisplay">
</markdown>
</div>

<div class="mt-3" *ngIf="justLinked">
<i class="fas fa-check-circle primary-text" style="font-size:50px;"></i>
<h4 class="mt-2" translate="plugins.settings.custom.homebridge-gsh.label_account_linked">
Account Linked
</h4>
<p class="primary-text">
<strong translate="plugins.settings.custom.homebridge-gsh.message_homebridge_restart_required"></strong>
</p>
Expand Down Expand Up @@ -99,4 +103,4 @@ <h4 class="mt-2" translate="plugins.settings.custom.homebridge-gsh.label_account
*ngIf="pluginConfig?.refreshToken || (pluginConfig?.email && pluginConfig?.password)"
[translate]="'form.button_save'">Save</button>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class HomebridgeRingComponent implements OnInit {
public phoneLastTwo: string;
public doingLogin = false;

public loaded = false;
public justLinked = false;
public pluginConfig;

Expand Down Expand Up @@ -80,6 +79,7 @@ export class HomebridgeRingComponent implements OnInit {
await this.saveConfig();
this.linkAccountForm.reset();
this.doingLogin = false;
this.twoFactorRequired = false;
},
(err) => {
this.doingLogin = false;
Expand Down