Initial create user support.

This commit is contained in:
Sergiotarxz 2023-11-17 23:16:54 +01:00
parent 2d1430ca87
commit 21d9f46d03
10 changed files with 185 additions and 43 deletions

View File

@ -28,6 +28,7 @@ my $build = Module::Build->new(
'List::AllUtils' => 0, 'List::AllUtils' => 0,
'Lingua::Stem::Snowball' => 0, 'Lingua::Stem::Snowball' => 0,
'Mojo::Redis' => 0, 'Mojo::Redis' => 0,
'DBIx::Class' => 0,
}, },
); );
$build->create_build_script; $build->create_build_script;

View File

@ -14,6 +14,7 @@ export default class Conquer {
private disableSetRotationOffset = false private disableSetRotationOffset = false
private conquerLogin: HTMLDivElement private conquerLogin: HTMLDivElement
private conquerLoginGoToRegister: HTMLAnchorElement private conquerLoginGoToRegister: HTMLAnchorElement
private conquerRegisterGoToLogin: HTMLAnchorElement
private conquerRegister: HTMLDivElement private conquerRegister: HTMLDivElement
private alpha = 0; private alpha = 0;
private beta = 0; private beta = 0;
@ -67,6 +68,13 @@ export default class Conquer {
this.conquerRegister.classList.remove('conquer-display-none') 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> { async removeLoginRegisterCombo(): Promise<void> {
this.conquerLogin.classList.add('conquer-display-none') this.conquerLogin.classList.add('conquer-display-none')
@ -79,6 +87,14 @@ export default class Conquer {
Conquer.fail('conquerRegister is invalid') Conquer.fail('conquerRegister is invalid')
} }
this.conquerRegister = conquerRegister 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() { async run() {
this.fillConquerLogin() this.fillConquerLogin()
@ -116,19 +132,7 @@ export default class Conquer {
maxZoom: 22, maxZoom: 22,
}), }),
}); });
this.setCenterDisplaced(37.58237, -5.96766) const proccessLocation = (location: GeolocationPosition) => {
navigator.geolocation.watchPosition((location) => {
this.setCenterDisplaced(location.coords.latitude, location.coords.longitude);
}, (err) => {
}, {
enableHighAccuracy: true
});
window.setInterval(() => {
this.disableSetRotationOffset = false
},10000);
window.setTimeout(() => {
window.setInterval(() => {
navigator.geolocation.getCurrentPosition((location) => {
this.currentLatitude = location.coords.latitude this.currentLatitude = location.coords.latitude
this.currentLongitude = location. coords.longitude this.currentLongitude = location. coords.longitude
if (location.coords.heading !== null && (this.alpha != 0 || this.beta != 0 || this.gamma != 0) && !this.disableSetRotationOffset) { if (location.coords.heading !== null && (this.alpha != 0 || this.beta != 0 || this.gamma != 0) && !this.disableSetRotationOffset) {
@ -137,9 +141,28 @@ export default class Conquer {
this.rotationOffset = this.compassHeading(this.alpha, this.beta, this.gamma) + (location.coords.heading*Math.PI*2)/360 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(this.currentLatitude, this.currentLongitude)
}, () => { }
this.setCenterDisplaced(37.58237, -5.96766)
navigator.geolocation.watchPosition((location) => {
proccessLocation(location)
}, (err) => {
return
}, { }, {
enableHighAccuracy: true enableHighAccuracy: true,
maximumAge: 0
});
window.setInterval(() => {
this.disableSetRotationOffset = false
}, 10000);
window.setTimeout(() => {
window.setInterval(() => {
navigator.geolocation.getCurrentPosition((location) => {
proccessLocation(location)
}, () => {
return
}, {
enableHighAccuracy: true,
maximumAge: 0
}) })
}, 1000) }, 1000)
}, 1000) }, 1000)

View File

@ -51,6 +51,7 @@ sub startup ($self) {
# $r->get('/:post')->to('Page#post'); # $r->get('/:post')->to('Page#post');
$r->get('/stats')->to('Metrics#stats'); $r->get('/stats')->to('Metrics#stats');
$r->get('/conquer')->to('Conquer#index'); $r->get('/conquer')->to('Conquer#index');
$r->put('/conquer/user')->to('UserConquer#create');
$r->get('/search.json')->to('Search#search'); $r->get('/search.json')->to('Search#search');
$r->get('/farmacia-guardia.json')->to('FarmaciaGuardia#current'); $r->get('/farmacia-guardia.json')->to('FarmaciaGuardia#current');
$r->get('/<:category>.rss')->to('Page#category_rss'); $r->get('/<:category>.rss')->to('Page#category_rss');

View File

@ -49,18 +49,26 @@ sub MIGRATIONS {
id_farmacia TEXT NOT NULL id_farmacia TEXT NOT NULL
);', );',
'CREATE INDEX farmacia_guardia_index on farmacia_guardia (date, id_farmacia, uuid);', '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) { sub _populate_locations ($dbh) {
require BurguillosInfo; # This subroutine crashes the migrations.
require BurguillosInfo::Tracking; # require BurguillosInfo;
my $tracking = BurguillosInfo::Tracking->new( BurguillosInfo->new ); # require BurguillosInfo::Tracking;
my $page = 0; # my $tracking = BurguillosInfo::Tracking->new( BurguillosInfo->new );
while (1) { # my $page = 0;
last if !_update_request_page( $dbh, $tracking, $page ); # while (1) {
$page += 100; # last if !_update_request_page( $dbh, $tracking, $page );
} # $page += 100;
# }
} }
sub _update_request_page ( $dbh, $tracking, $page ) { sub _update_request_page ( $dbh, $tracking, $page ) {

View 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;

View 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;

View File

@ -17,12 +17,15 @@ body {
top: calc( 50% - 200px - 10px); top: calc( 50% - 200px - 10px);
left: calc( 50% - 150px - 10px); left: calc( 50% - 150px - 10px);
padding: 10px; padding: 10px;
justify-content: center;
height: 400px; height: 400px;
width: 300px; width: 300px;
z-index: 1; }
body div.conquer-login form, body div.conquer-register form {
width: 100%;
height: 100%;
display: flex; display: flex;
z-index: 1; flex-direction: column;
flex-direction: column; } justify-content: center; }
body div.conquer-display-none { body div.conquer-display-none {
display: none; } display: none; }
body div.conquer-container { body div.conquer-container {

View File

@ -17,6 +17,13 @@ html {
body { body {
div.conquer-login,div.conquer-register { div.conquer-login,div.conquer-register {
form {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
}
position: fixed; position: fixed;
color: black; color: black;
font-size: 25px; font-size: 25px;
@ -25,13 +32,9 @@ body {
top: calc( 50% - 200px - 10px ); top: calc( 50% - 200px - 10px );
left: calc( 50% - 150px - 10px ); left: calc( 50% - 150px - 10px );
padding: 10px; padding: 10px;
justify-content: center;
height: 400px; height: 400px;
width: 300px; width: 300px;
display: flex;
z-index: 1; z-index: 1;
flex-direction: column;
} }
div.conquer-display-none { div.conquer-display-none {
display: none; display: none;

File diff suppressed because one or more lines are too long

View File

@ -9,22 +9,26 @@
</head> </head>
<body> <body>
<div class="conquer-login conquer-display-none"> <div class="conquer-login conquer-display-none">
<form>
<label>Nombre de usuario</label> <label>Nombre de usuario</label>
<input class="conquer-login-username"/> <input class="conquer-login-username"/>
<label>Contraseña</label> <label>Contraseña</label>
<input class="conquer-login-password" type="password"/> <input class="conquer-login-password" type="password"/>
<button class="conquer-login-sumbit">Iniciar sesión</button> <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>¿No tienes cuenta aun? <a href="#" class="conquer-login-go-to-register">Registrate</a></p>
</form>
</div> </div>
<div class="conquer-register conquer-display-none"> <div class="conquer-register conquer-display-none">
<form>
<label>Nombre de usuario</label> <label>Nombre de usuario</label>
<input class="conquer-register-username"/> <input class="conquer-register-username"/>
<label>Contraseña</label> <label>Contraseña</label>
<input class="conquer-register-password" type="password"/> <input class="conquer-register-password" type="password"/>
<label>Repite la contraseña</label> <label>Repite la contraseña</label>
<input class="conquer-register-repeat-password" type="password"/> <input class="conquer-register-repeat-password" type="password"/>
<button class="conquer-register-sumbit">Iniciar sesión</button> <button class="conquer-register-sumbit">Finaliza el registro</button>
<p>¿Ya estás registrado? <a href="#" class="conquer-register-go-to-login">Registrate.</a> <p>¿Ya estás registrado? <a href="#" class="conquer-register-go-to-login">Inicia Sesión</a>.</p>
</form>
</div> </div>
<div class="conquer-container"> <div class="conquer-container">
</div> </div>