Skip to content

Commit

Permalink
Merge pull request #187 from UB-ES-2020/develop
Browse files Browse the repository at this point in the history
Sprint 4
  • Loading branch information
xavi2411 authored Dec 14, 2020
2 parents d58fa42 + 9b44c55 commit c3c945b
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 53 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function register(Request $request)
$token = $user->createToken('authToken');

return $request->wantsJson()
? new JsonResponse(['data' => $user, 'access_token' => $token->accessToken], 201)
? new JsonResponse(['data' => $user->fresh(), 'access_token' => $token->accessToken], 201)
: redirect($this->redirectPath());
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/UserViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

class UserViewController extends Controller
{
public function userAccountPage()
public function userAccountPage(Request $request)
{
return view('user.account');
$tab = $request->input('tab') ? $request->input('tab') : "info-user";
return view('user.account', ['tab'=>$tab]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class SetDefaultNameToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('name')->default('Usuario')->change();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->string('name')->default(null)->change();
});
}
}
2 changes: 1 addition & 1 deletion resources/js/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</svg></a>
</div>
<div class="header-links">
<a id="help-link" class="help-link" href="/help"><strong>Ayuda</strong></a>
<a id="help-link" class="help-link" href="#"><strong>Ayuda</strong></a>
<a id="register-link" v-if="!username && login_form !== undefined" class="register-link" href="/register"><strong>Regístrate</strong></a>
<a id="login-link" v-if="!username && login_form === undefined" class="login-link" href="/login"><strong>Inicia sesión</strong></a>
<div class="dropdown">
Expand Down
7 changes: 6 additions & 1 deletion resources/js/components/MainPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</svg></a>
</div>
<div class="header-links">
<a id="help-link" class="help-link" href="/help"><strong style="color: #FFF;">Ayuda</strong></a>
<a id="help-link" class="help-link" href="#"><strong style="color: #FFF;">Ayuda</strong></a>
<a id="for-you-link" class="login-link" href="#">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
<g id="icon-/-gift" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
Expand Down Expand Up @@ -178,6 +178,11 @@
window.location.href = "/restaurants?address=" + formatted_address + "&zip=" + zip;
}
},
logout:function() {
window.localStorage.removeItem('auth_token');
window.localStorage.removeItem('username');
window.location.reload();
}
},
computed: {
username: function() {
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
},
)
.then(response => {
console.log(response)
window.localStorage.setItem('auth_token', response.data.access_token);
window.localStorage.setItem('username', response.data.data.name);
window.location.href = '/';
})
.catch((error) => {
Expand Down
32 changes: 24 additions & 8 deletions resources/js/components/RestaurantPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</svg></a>
</div>
<div class="header-links">
<a id="help-link" class="help-link" href="/help"><strong style="color: #FFF;">Ayuda</strong></a>
<a id="help-link" class="help-link" href="#"><strong style="color: #FFF;">Ayuda</strong></a>
<a id="for-you-link" class="login-link" href="#">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
<g id="icon-/-gift" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
Expand All @@ -29,13 +29,24 @@
</svg>
<strong style="color: #FFF;">Inicia sesión</strong>
</a>
<a id="account-link" v-if="username" class="my-account-link" href="/account/info">
<svg width="20" height="22" viewBox="0 0 12 13" xmlns="http://www.w3.org/2000/svg" class="c-nav-icon">
<path d="M2.67 11.33V9a.33.33 0 0 1 .66 0v2.67c0 .18-.15.33-.33.33H1.67a1 1 0 0 1-1-1V9.67c0-2.6 1.8-4.34 5.33-4.34 3.53 0 5.33 1.74 5.33 4.34V11a1 1 0 0 1-1 1H9a.33.33 0 0 1-.33-.33V9a.33.33 0 1 1 .66 0v2.33h1c.19 0 .34-.15.34-.33V9.67C10.67 7.44 9.17 6 6 6S1.33 7.44 1.33 9.67V11c0 .18.15.33.34.33h1zm3.33-6c1.09 0 2-1.02 2-2.33C8 1.7 7.09.67 6 .67 4.91.67 4 1.69 4 3c0 1.3.91 2.33 2 2.33zM6 6C4.53 6 3.33 4.66 3.33 3S4.53 0 6 0s2.67 1.34 2.67 3S7.47 6 6 6zm2.67 3.67a.33.33 0 1 1 .66 0v2c0 .09-.03.17-.1.23-.12.12-.37.28-.8.42-.65.22-1.56.35-2.76.35-.92 0-1.65-.14-2.21-.36-.36-.14-.58-.3-.7-.4a.33.33 0 0 1-.1-.24v-2a.33.33 0 1 1 .67 0v1.84a5.33 5.33 0 0 0 2.33.5c1.14-.01 1.98-.13 2.57-.33.2-.07.35-.13.44-.18V9.67z" fill="#266ABD">
</path>
</svg>
<strong>{{username}}</strong>
</a>
<div class="dropdown" style="right: 150px">
<a id="account-link" v-if="username" class="my-account-link">
<svg width="20" height="22" viewBox="0 0 12 13" xmlns="http://www.w3.org/2000/svg" class="c-nav-icon">
<path d="M2.67 11.33V9a.33.33 0 0 1 .66 0v2.67c0 .18-.15.33-.33.33H1.67a1 1 0 0 1-1-1V9.67c0-2.6 1.8-4.34 5.33-4.34 3.53 0 5.33 1.74 5.33 4.34V11a1 1 0 0 1-1 1H9a.33.33 0 0 1-.33-.33V9a.33.33 0 1 1 .66 0v2.33h1c.19 0 .34-.15.34-.33V9.67C10.67 7.44 9.17 6 6 6S1.33 7.44 1.33 9.67V11c0 .18.15.33.34.33h1zm3.33-6c1.09 0 2-1.02 2-2.33C8 1.7 7.09.67 6 .67 4.91.67 4 1.69 4 3c0 1.3.91 2.33 2 2.33zM6 6C4.53 6 3.33 4.66 3.33 3S4.53 0 6 0s2.67 1.34 2.67 3S7.47 6 6 6zm2.67 3.67a.33.33 0 1 1 .66 0v2c0 .09-.03.17-.1.23-.12.12-.37.28-.8.42-.65.22-1.56.35-2.76.35-.92 0-1.65-.14-2.21-.36-.36-.14-.58-.3-.7-.4a.33.33 0 0 1-.1-.24v-2a.33.33 0 1 1 .67 0v1.84a5.33 5.33 0 0 0 2.33.5c1.14-.01 1.98-.13 2.57-.33.2-.07.35-.13.44-.18V9.67z" fill="#FFF">
</path>
</svg>
<strong style="color: #FFF">{{username}}</strong>
</a>
<div class="dropdown-content">
<a href="/account?tab=info-user"><p>Información de la cuenta</p></a>
<a href="/account?tab=pedidos"><p>Pedidos</p></a>
<a href="/account?tab=dir-reparto"><p>Crédito de la cuenta</p></a>
<!-- <a href="/account?tab="><p>Métodos de pago</p></a>
<a href="/account?tab="><p>Direcciones de reparto</p></a> -->
<a href="/account?tab=contacto"><p>Preferencias de contacto</p></a>
<a href="#" v-on:click="logout"><p>Salir</p></a>
</div>
</div>
</div>
</div>
<div class="restaurant-breadcrumb mt-4">
Expand Down Expand Up @@ -410,6 +421,11 @@
window.location.href = '/login';
}
});
},
logout:function() {
window.localStorage.removeItem('auth_token');
window.localStorage.removeItem('username');
window.location.reload();
}
},
computed: {
Expand Down
42 changes: 17 additions & 25 deletions resources/js/components/UserAccount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
</div>
</div>

<main class="restaurant-products-container" v-if="tab_selected === 'info-user'">
<main class="restaurant-products-container" v-if="tab_selected === 'info-user'">
<section>
<user-information :id="user.id" :name="user.name" :email="user.email" :phone="user.phone"></user-information>
<user-information :user="user"></user-information>
</section>
</main>

Expand All @@ -42,7 +42,7 @@

<main class="restaurant-products-container" v-if="tab_selected === 'contacto'">
<section>
<user-contact :id="user.id" :sms_offers="user.sms_offers" :email_offers="user.email_offers"></user-contact>
<user-contact :user="user"></user-contact>
</section>
</main>
</div>
Expand All @@ -53,6 +53,8 @@
export default {
name: "UserManagementPage",
props: ["tab"],
data() {
return {
user: "",
Expand All @@ -73,17 +75,18 @@
window.location.href = '/login';
}
});
this.change_tab(this.tab);
},
methods: {
change_tab: function(tab) {
if (tab === 'info-user') {
$('#info-user').addClass('option-selected');
if (tab === 'contacto') {
$('#contacto').addClass('option-selected');
$('#pedidos').removeClass('option-selected');
$('#dir-reparto').removeClass('option-selected');
$('#contacto').removeClass('option-selected');
this.tab_selected = 'info-user';
this.name_tab_selected = 'Información de la cuenta';
$('#info-user').removeClass('option-selected');
this.tab_selected = 'contacto';
this.name_tab_selected = 'Preferencias de contacto';
} else if(tab === 'pedidos'){
$('#pedidos').addClass('option-selected');
$('#info-user').removeClass('option-selected');
Expand All @@ -99,26 +102,15 @@
this.tab_selected = 'dir-reparto';
this.name_tab_selected = 'Direcciones de reparto';
} else{
$('#contacto').addClass('option-selected');
$('#info-user').addClass('option-selected');
$('#pedidos').removeClass('option-selected');
$('#dir-reparto').removeClass('option-selected');
$('#info-user').removeClass('option-selected');
this.tab_selected = 'contacto';
this.name_tab_selected = 'Preferencias de contacto';
$('#contacto').removeClass('option-selected');
this.tab_selected = 'info-user';
this.name_tab_selected = 'Información de la cuenta';
}
},
},
computed: {
username: function() {
var username = window.localStorage.getItem('username');
if (username && username !== undefined && username !== "undefined") {
if (username != "null") {
return username
} else {
return "Mi Cuenta";
}
}
}
},
};
</script>
</script>
12 changes: 6 additions & 6 deletions resources/js/components/UserContact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<div class="check-block">
<h4>Recibe ofertas y descuentos por</h4>
<div class="form-check">
<input id="sms_offers" type="checkbox" v-model="sms_offers">
<input id="sms_offers" type="checkbox" v-model="user.sms_offers">
<label class="check-label" for="sms_offers">SMS</label>
</div>
<div class="form-check">
<input id="email_offers" type="checkbox" v-model="email_offers">
<input id="email_offers" type="checkbox" v-model="user.email_offers">
<label class="check-label" for="email_offers">Email</label>
</div>
</div>
Expand All @@ -45,18 +45,18 @@
<script>
export default {
name: "UserInfo",
props: ['sms_offers', 'email_offers', 'id'],
props: ['user'],
data() {
return {
}
},
methods: {
save(event) {
event.preventDefault();
window.axios.put('user/' + this.id,
window.axios.put('user/' + this.user.id,
{
sms_offers: this.sms_offers,
email_offers: this.email_offers,
sms_offers: this.user.sms_offers,
email_offers: this.user.email_offers,
},
)
.then(response => {
Expand Down
16 changes: 8 additions & 8 deletions resources/js/components/UserInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

<div>
<span>Nombre</span>
<input name="name" class="info-input" v-model="name" placeholder="Introduce tu nombre completo" type="text" required>
<input name="name" class="info-input" v-model="user.name" placeholder="Introduce tu nombre completo" type="text" required>
</div>
<div>
<span>E-mail</span>
<input name="email" class="info-input" v-model="email" placeholder="Introduce tu email" type="email" value="email_holder" required>
<input name="email" class="info-input" v-model="user.email" placeholder="Introduce tu email" type="email" value="email_holder" required>
</div>
<div>
<span>Número de teléfono</span>
<input name="phone" class="info-input" v-model="phone" placeholder="Introduce tu número de teléfono" type="text" value="phone_number" required>
<input name="phone" class="info-input" v-model="user.phone" placeholder="Introduce tu número de teléfono" type="text" value="phone_number" required>
</div>


Expand All @@ -34,19 +34,19 @@
<script>
export default {
name: "UserInfo",
props: ['name', 'email', 'phone', 'id'],
props: ['user'],
data() {
return {
}
},
methods: {
save(event) {
event.preventDefault();
window.axios.put('user/' + this.id,
window.axios.put('user/' + this.user.id,
{
name: this.name,
email: this.email,
phone: this.phone,
name: this.user.name,
email: this.user.email,
phone: this.user.phone,
},
)
.then(response => {
Expand Down
1 change: 1 addition & 0 deletions resources/sass/_restaurant.scss
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
width: 33.33%;

.restaurant-cart-container {
max-width: 390px;
text-align: left;
background: #FFF;
border: 1px solid #e2e6e9;
Expand Down
2 changes: 1 addition & 1 deletion resources/views/user/account.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@endsection

@section('content')
<user-account>
<user-account tab="{{$tab}}">
</user-account>
@endsection

Expand Down

0 comments on commit c3c945b

Please sign in to comment.