Initial create user support.
This commit is contained in:
parent
2d1430ca87
commit
21d9f46d03
1
Build.PL
1
Build.PL
@ -28,6 +28,7 @@ my $build = Module::Build->new(
|
||||
'List::AllUtils' => 0,
|
||||
'Lingua::Stem::Snowball' => 0,
|
||||
'Mojo::Redis' => 0,
|
||||
'DBIx::Class' => 0,
|
||||
},
|
||||
);
|
||||
$build->create_build_script;
|
||||
|
@ -14,6 +14,7 @@ export default class Conquer {
|
||||
private disableSetRotationOffset = false
|
||||
private conquerLogin: HTMLDivElement
|
||||
private conquerLoginGoToRegister: HTMLAnchorElement
|
||||
private conquerRegisterGoToLogin: HTMLAnchorElement
|
||||
private conquerRegister: HTMLDivElement
|
||||
private alpha = 0;
|
||||
private beta = 0;
|
||||
@ -67,6 +68,13 @@ export default class Conquer {
|
||||
this.conquerRegister.classList.remove('conquer-display-none')
|
||||
}
|
||||
}
|
||||
async goToLogin(): Promise<void> {
|
||||
const isLogged = await this.isLogged();
|
||||
await this.removeLoginRegisterCombo()
|
||||
if (!isLogged) {
|
||||
this.conquerLogin.classList.remove('conquer-display-none')
|
||||
}
|
||||
}
|
||||
|
||||
async removeLoginRegisterCombo(): Promise<void> {
|
||||
this.conquerLogin.classList.add('conquer-display-none')
|
||||
@ -79,6 +87,14 @@ export default class Conquer {
|
||||
Conquer.fail('conquerRegister is invalid')
|
||||
}
|
||||
this.conquerRegister = conquerRegister
|
||||
const conquerRegisterGoToLogin = document.querySelector('.conquer-register-go-to-login')
|
||||
if (conquerRegisterGoToLogin === null || !(conquerRegisterGoToLogin instanceof HTMLAnchorElement)) {
|
||||
Conquer.fail('Link to go to login from register is invalid.')
|
||||
}
|
||||
this.conquerRegisterGoToLogin = conquerRegisterGoToLogin
|
||||
this.conquerRegisterGoToLogin.addEventListener('click', () => {
|
||||
this.goToLogin()
|
||||
})
|
||||
}
|
||||
async run() {
|
||||
this.fillConquerLogin()
|
||||
@ -116,30 +132,37 @@ export default class Conquer {
|
||||
maxZoom: 22,
|
||||
}),
|
||||
});
|
||||
const proccessLocation = (location: GeolocationPosition) => {
|
||||
this.currentLatitude = location.coords.latitude
|
||||
this.currentLongitude = location. coords.longitude
|
||||
if (location.coords.heading !== null && (this.alpha != 0 || this.beta != 0 || this.gamma != 0) && !this.disableSetRotationOffset) {
|
||||
this.disableSetRotationOffset = true
|
||||
this.heading = location.coords.heading
|
||||
this.rotationOffset = this.compassHeading(this.alpha, this.beta, this.gamma) + (location.coords.heading*Math.PI*2)/360
|
||||
}
|
||||
this.setCenterDisplaced(this.currentLatitude, this.currentLongitude)
|
||||
}
|
||||
this.setCenterDisplaced(37.58237, -5.96766)
|
||||
navigator.geolocation.watchPosition((location) => {
|
||||
this.setCenterDisplaced(location.coords.latitude, location.coords.longitude);
|
||||
proccessLocation(location)
|
||||
}, (err) => {
|
||||
return
|
||||
}, {
|
||||
enableHighAccuracy: true
|
||||
enableHighAccuracy: true,
|
||||
maximumAge: 0
|
||||
});
|
||||
window.setInterval(() => {
|
||||
this.disableSetRotationOffset = false
|
||||
},10000);
|
||||
}, 10000);
|
||||
window.setTimeout(() => {
|
||||
window.setInterval(() => {
|
||||
navigator.geolocation.getCurrentPosition((location) => {
|
||||
this.currentLatitude = location.coords.latitude
|
||||
this.currentLongitude = location. coords.longitude
|
||||
if (location.coords.heading !== null && (this.alpha != 0 || this.beta != 0 || this.gamma != 0) && !this.disableSetRotationOffset) {
|
||||
this.disableSetRotationOffset = true
|
||||
this.heading = location.coords.heading
|
||||
this.rotationOffset = this.compassHeading(this.alpha, this.beta, this.gamma) + (location.coords.heading*Math.PI*2)/360
|
||||
}
|
||||
this.setCenterDisplaced(this.currentLatitude, this.currentLongitude)
|
||||
proccessLocation(location)
|
||||
}, () => {
|
||||
return
|
||||
}, {
|
||||
enableHighAccuracy: true
|
||||
enableHighAccuracy: true,
|
||||
maximumAge: 0
|
||||
})
|
||||
}, 1000)
|
||||
}, 1000)
|
||||
|
@ -51,6 +51,7 @@ sub startup ($self) {
|
||||
# $r->get('/:post')->to('Page#post');
|
||||
$r->get('/stats')->to('Metrics#stats');
|
||||
$r->get('/conquer')->to('Conquer#index');
|
||||
$r->put('/conquer/user')->to('UserConquer#create');
|
||||
$r->get('/search.json')->to('Search#search');
|
||||
$r->get('/farmacia-guardia.json')->to('FarmaciaGuardia#current');
|
||||
$r->get('/<:category>.rss')->to('Page#category_rss');
|
||||
|
@ -49,18 +49,26 @@ sub MIGRATIONS {
|
||||
id_farmacia TEXT NOT NULL
|
||||
);',
|
||||
'CREATE INDEX farmacia_guardia_index on farmacia_guardia (date, id_farmacia, uuid);',
|
||||
'CREATE TABLE conquer_user (
|
||||
uuid UUID NOT NULL PRIMARY KEY,
|
||||
username TEXT NOT NULL UNIQUE,
|
||||
encrypted_password TEXT NOT NULL,
|
||||
last_activity TEXT NOT NULL DEFAULT NOW(),
|
||||
is_admin boolean NOT NULL DEFAULT false
|
||||
);',
|
||||
);
|
||||
}
|
||||
|
||||
sub _populate_locations ($dbh) {
|
||||
require BurguillosInfo;
|
||||
require BurguillosInfo::Tracking;
|
||||
my $tracking = BurguillosInfo::Tracking->new( BurguillosInfo->new );
|
||||
my $page = 0;
|
||||
while (1) {
|
||||
last if !_update_request_page( $dbh, $tracking, $page );
|
||||
$page += 100;
|
||||
}
|
||||
# This subroutine crashes the migrations.
|
||||
# require BurguillosInfo;
|
||||
# require BurguillosInfo::Tracking;
|
||||
# my $tracking = BurguillosInfo::Tracking->new( BurguillosInfo->new );
|
||||
# my $page = 0;
|
||||
# while (1) {
|
||||
# last if !_update_request_page( $dbh, $tracking, $page );
|
||||
# $page += 100;
|
||||
# }
|
||||
}
|
||||
|
||||
sub _update_request_page ( $dbh, $tracking, $page ) {
|
||||
|
61
lib/BurguillosInfo/Schema.pm
Normal file
61
lib/BurguillosInfo/Schema.pm
Normal file
@ -0,0 +1,61 @@
|
||||
package BurguillosInfo::Schema;
|
||||
|
||||
use v5.36.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
our $VERSION = 1;
|
||||
|
||||
use feature 'signatures';
|
||||
|
||||
use BurguillosInfo;
|
||||
|
||||
use parent 'DBIx::Class::Schema';
|
||||
|
||||
__PACKAGE__->load_namespaces();
|
||||
|
||||
my $schema;
|
||||
|
||||
sub Schema ($class) {
|
||||
if ( !defined $schema ) {
|
||||
my $app = BurguillosInfo->new;
|
||||
my $config = $app->{config};
|
||||
my $database_config = $config->{db};
|
||||
my $dbname = $database_config->{database};
|
||||
my $host = $database_config->{host};
|
||||
my $port = $database_config->{port};
|
||||
my $user = $database_config->{user};
|
||||
my $password = $database_config->{password};
|
||||
my $dsn = 'dbi:Pg:';
|
||||
|
||||
if ( !defined $dbname ) {
|
||||
die "The key database/dbname must be configured.";
|
||||
}
|
||||
$dsn .= "dbname=$dbname";
|
||||
if ( defined $host ) {
|
||||
$dsn .= ";host=$host";
|
||||
}
|
||||
if ( defined $port ) {
|
||||
$dsn .= ";port=$port";
|
||||
}
|
||||
|
||||
# Undef is perfectly fine for username and password.
|
||||
$schema = $class->connect(
|
||||
$dsn, $user,
|
||||
$password,
|
||||
{
|
||||
auto_savepoint => 1,
|
||||
Callbacks => {
|
||||
connected => sub {
|
||||
shift->do('set timezone = UTC');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return $schema;
|
||||
}
|
||||
1;
|
38
lib/BurguillosInfo/Schema/Result/ConquerUser.pm
Normal file
38
lib/BurguillosInfo/Schema/Result/ConquerUser.pm
Normal file
@ -0,0 +1,38 @@
|
||||
package BurguillosInfo::Schema::Result::ConquerUser;
|
||||
|
||||
use v5.36.0;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent 'DBIx::Class::Core';
|
||||
|
||||
__PACKAGE__->table('players');
|
||||
|
||||
__PACKAGE__->add_columns(
|
||||
uuid => {
|
||||
data_type => 'uuid',
|
||||
is_nullable => 0,
|
||||
},
|
||||
username => {
|
||||
data_type => 'text',
|
||||
is_nullable => 0,
|
||||
},
|
||||
encrypted_password => {
|
||||
data_type => 'text',
|
||||
is_nullable => 0,
|
||||
},
|
||||
last_activity => {
|
||||
data_type => 'timestamp',
|
||||
is_nullable => 0,
|
||||
default_value => \'NOW()',
|
||||
},
|
||||
is_admin => {
|
||||
data_type => 'boolean',
|
||||
is_nullable => 0,
|
||||
default_value => \'0',
|
||||
}
|
||||
);
|
||||
__PACKAGE__->set_primary_key('uuid');
|
||||
__PACKAGE__->add_unique_constraint("unique_constraint_username", ['username']);
|
||||
1;
|
@ -17,12 +17,15 @@ body {
|
||||
top: calc( 50% - 200px - 10px);
|
||||
left: calc( 50% - 150px - 10px);
|
||||
padding: 10px;
|
||||
justify-content: center;
|
||||
height: 400px;
|
||||
width: 300px;
|
||||
display: flex;
|
||||
z-index: 1;
|
||||
flex-direction: column; }
|
||||
z-index: 1; }
|
||||
body div.conquer-login form, body div.conquer-register form {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center; }
|
||||
body div.conquer-display-none {
|
||||
display: none; }
|
||||
body div.conquer-container {
|
||||
|
@ -17,6 +17,13 @@ html {
|
||||
|
||||
body {
|
||||
div.conquer-login,div.conquer-register {
|
||||
form {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
}
|
||||
position: fixed;
|
||||
color: black;
|
||||
font-size: 25px;
|
||||
@ -25,13 +32,9 @@ body {
|
||||
top: calc( 50% - 200px - 10px );
|
||||
left: calc( 50% - 150px - 10px );
|
||||
padding: 10px;
|
||||
justify-content: center;
|
||||
height: 400px;
|
||||
width: 300px;
|
||||
display: flex;
|
||||
z-index: 1;
|
||||
flex-direction: column;
|
||||
|
||||
}
|
||||
div.conquer-display-none {
|
||||
display: none;
|
||||
|
File diff suppressed because one or more lines are too long
@ -9,22 +9,26 @@
|
||||
</head>
|
||||
<body>
|
||||
<div class="conquer-login conquer-display-none">
|
||||
<label>Nombre de usuario</label>
|
||||
<input class="conquer-login-username"/>
|
||||
<label>Contraseña</label>
|
||||
<input class="conquer-login-password" type="password"/>
|
||||
<button class="conquer-login-sumbit">Iniciar sesión</button>
|
||||
<p>¿No tienes cuenta aun? <a href="#" class="conquer-login-go-to-register">Registrate.</a>
|
||||
<form>
|
||||
<label>Nombre de usuario</label>
|
||||
<input class="conquer-login-username"/>
|
||||
<label>Contraseña</label>
|
||||
<input class="conquer-login-password" type="password"/>
|
||||
<button class="conquer-login-sumbit">Inicia sesión</button>
|
||||
<p>¿No tienes cuenta aun? <a href="#" class="conquer-login-go-to-register">Registrate</a></p>
|
||||
</form>
|
||||
</div>
|
||||
<div class="conquer-register conquer-display-none">
|
||||
<label>Nombre de usuario</label>
|
||||
<input class="conquer-register-username"/>
|
||||
<label>Contraseña</label>
|
||||
<input class="conquer-register-password" type="password"/>
|
||||
<label>Repite la contraseña</label>
|
||||
<input class="conquer-register-repeat-password" type="password"/>
|
||||
<button class="conquer-register-sumbit">Iniciar sesión</button>
|
||||
<p>¿Ya estás registrado? <a href="#" class="conquer-register-go-to-login">Registrate.</a>
|
||||
<form>
|
||||
<label>Nombre de usuario</label>
|
||||
<input class="conquer-register-username"/>
|
||||
<label>Contraseña</label>
|
||||
<input class="conquer-register-password" type="password"/>
|
||||
<label>Repite la contraseña</label>
|
||||
<input class="conquer-register-repeat-password" type="password"/>
|
||||
<button class="conquer-register-sumbit">Finaliza el registro</button>
|
||||
<p>¿Ya estás registrado? <a href="#" class="conquer-register-go-to-login">Inicia Sesión</a>.</p>
|
||||
</form>
|
||||
</div>
|
||||
<div class="conquer-container">
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user