-
Notifications
You must be signed in to change notification settings - Fork 0
Adds Getty functionality for badge sign on/ adds date checking #3
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
Open
jsiems
wants to merge
19
commits into
Dev
Choose a base branch
from
getty
base: Dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b9ac4ad
Adds badge registration to the register page
jsiems 0ddf4f5
Adds new functionaliy to getty, and checks the date and times before …
jsiems 7232fb9
Adds getty file
jsiems 522dbc7
Adds functionality for unlocking from local wifi
jsiems 893b8c1
Merge pull request #1 from KeystoneIT/getty_test
jsiems 9082883
Removes unused paramter
jsiems f3ab1dc
Removed unused code
jsiems 9787a55
Removed console.log statements
jsiems 9991eec
Replaces all user agent with Mojo::UserAgent
jsiems f0e85db
Changes database to all be on one version
jsiems dfdc7bb
unlock door method added
jsiems f503cd6
change ofd to open_front_door
jsiems 39c46b5
Adds model support for files
jsiems 9bc77ff
Adds models
jsiems fcdfca4
Error box does not dissapear at the wrong time anymore
jsiems 4bfd14d
ask to input pin if no pin is detected
jsiems 9762d56
Hides id box when badges are not shown
jsiems 96e60b8
fix mixed content when https
jsiems 48d1a71
All changes made for getty and normal web control brought up in our s…
jsiems File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| { | ||
| pg => 'postgresql://doorcontrol:doorcontrol@/doorcontrol', | ||
| unlock_url => 'theofficialjosh.com/test', | ||
| lock_url => 'theofficialjosh.com/test', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package DoorControl::Command::getty; | ||
| use Mojo::Base 'Mojolicious::Command'; | ||
| use Date::Manip; | ||
| use Mojo::UserAgent; | ||
|
|
||
| has description => 'Show versions of available modules'; | ||
| has usage => sub { shift->extract_usage }; | ||
|
|
||
| sub run { | ||
| my $self = shift; | ||
|
|
||
| while(1) { | ||
| my $userinput = <STDIN>; | ||
| my $results = "FAILED"; | ||
| chomp ($userinput); | ||
|
|
||
| my $user = $self->app->authenticate->authenticateBadge($userinput); | ||
|
|
||
| $results = $self->app->doorcontrol->unlock($user->{authorized}, 0) ? "SUCCESS" : "FAILED"; | ||
|
|
||
| if(defined $user->{name}) { | ||
| $userinput = $user->{name}; | ||
| } | ||
|
|
||
| $self->app->logger->log($userinput, "unlock", $results, "badge"); | ||
| } | ||
| } | ||
|
|
||
| 1; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package DoorControl::Model::Authenticate; | ||
| use Mojo::Base -base; | ||
|
|
||
| has 'pg'; | ||
|
|
||
| sub authenticateUser { | ||
| my ($self, $name, $pin) = @_; | ||
|
|
||
| my $user = $self->pg->db->query("select * from users where name = ? and pin = ?", $name, $pin)->hash; | ||
|
|
||
| return $user->{authorized}; | ||
| } | ||
|
|
||
| sub authenticateBadge { | ||
| my ($self, $badge) = @_; | ||
|
|
||
| my $user = $self->pg->db->query("select * from badges where badge_id = ?;", $badge)->hash; | ||
|
|
||
| return $user; | ||
| } | ||
|
|
||
| 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package DoorControl::Model::DoorControl; | ||
| use Mojo::Base -base; | ||
|
|
||
| use Date::Manip; | ||
|
|
||
| has 'FULL_AUTHORIZATION'; | ||
| has 'LIMITED_AUTHORIZATION'; | ||
| has 'unlock_url'; | ||
| has 'lock_url'; | ||
|
|
||
| sub unlock { | ||
| my ($self, $authorized, $internal) = @_; | ||
|
|
||
| my $results = 0; | ||
|
|
||
| if($authorized == $self->FULL_AUTHORIZATION || $internal || ($authorized == $self->LIMITED_AUTHORIZATION && Date_IsWorkDay(ParseDate('now'), 1))) { | ||
| my $ua = Mojo::UserAgent->new; | ||
| $results = $ua->get($self->unlock_url)->res->code == 200 ? 1 : 0; | ||
| } | ||
|
|
||
| return $results; | ||
| } | ||
|
|
||
| sub lock { | ||
| my ($self) = @_; | ||
|
|
||
| my $results = 0; | ||
|
|
||
| my $ua = Mojo::UserAgent->new; | ||
| $results = $ua->get($self->lock_url)->res->code == 200 ? 1 : 0; | ||
|
|
||
| return $results; | ||
| } | ||
|
|
||
| 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package DoorControl::Model::Log; | ||
| use Mojo::Base -base; | ||
|
|
||
| has 'pg'; | ||
|
|
||
| sub log { | ||
| my ($self, $name, $action, $results, $method) = @_; | ||
|
|
||
| $self->pg->db->query("insert into log (name, action, result, method) values (?, ?, ?, ?);", $name, $action, $results, $method); | ||
|
|
||
| return 1; | ||
| } | ||
|
|
||
| sub getLog { | ||
| my ($self, $limit) = @_; | ||
|
|
||
| return $self->pg->db->query("select id, action, method, result, name, created from log order by created desc limit ?;", $limit)->hashes->to_array; | ||
| } | ||
|
|
||
| 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package DoorControl::Model::Register; | ||
| use Mojo::Base -base; | ||
|
|
||
| has 'pg'; | ||
|
|
||
| sub insertUser { | ||
| my ($self, $newName, $newPin, $auth) = @_; | ||
|
|
||
| $self->pg->db->query("insert into users (name, pin, authorized) values (?, ?, ?);", $newName, $newPin, $auth); | ||
|
|
||
| return 1; | ||
| } | ||
|
|
||
| sub getBadges { | ||
| my ($self, $start, $end) = @_; | ||
|
|
||
| $self->pg->db->query("select * from badges where badge_id >= ? and badge_id <= ?", $start, $end)->hashes->to_array; | ||
|
|
||
| } | ||
|
|
||
| sub deleteBadge { | ||
| my ($self, $badge) = @_; | ||
|
|
||
| $self->pg->db->query("delete from badges where badge_id = ?", $badge); | ||
|
|
||
| return 1; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| sub insertBadge { | ||
| my ($self, $badge, $newName, $auth) = @_; | ||
|
|
||
| $self->pg->db->query("insert into badges (badge_id, name, authorized) values (?, ?, ?);", $badge, $newName, $auth); | ||
|
|
||
| return 1; | ||
| } | ||
|
|
||
| 1; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the Model.