Merge branch 'release/2.0.1'

This commit is contained in:
Bubka 2020-12-03 20:28:04 +01:00
commit a2baab1f65
15 changed files with 137 additions and 22 deletions

View File

@ -7,6 +7,7 @@
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
use App\Http\Requests\CaseInsensitiveLogin;
use Illuminate\Validation\ValidationException;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Carbon\Carbon;
@ -35,9 +36,8 @@ class LoginController extends Controller
*
* @throws \Illuminate\Validation\ValidationException
*/
public function login(Request $request)
public function login(CaseInsensitiveLogin $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
@ -105,6 +105,22 @@ protected function sendLockoutResponse(Request $request)
return response()->json(['message' => Lang::get('auth.throttle', ['seconds' => $seconds])], Response::HTTP_TOO_MANY_REQUESTS);
}
/**
* Get the needed authorization credentials from the request.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function credentials(Request $request)
{
$credentials = [
$this->username() => strtolower($request->input($this->username())),
'password' => $request->get('password'),
];
return $credentials;
}
/**
* Validate the user login request.
@ -117,7 +133,7 @@ protected function sendLockoutResponse(Request $request)
protected function validateLogin(Request $request)
{
$request->validate([
$this->username() => 'required|string|exists:users,email',
$this->username() => 'required|email|exists:users,email',
'password' => 'required|string',
]);
}

View File

@ -33,9 +33,9 @@ class RegisterController extends Controller
*/
public function checkUser()
{
$username = DB::table('users')->where('id', 1)->value('name');
$user = DB::table('users')->first();
return response()->json(['username' => $username], 200);
return response()->json(['username' => isset($user->name) ? $user->name : null], 200);
}
/**

View File

@ -0,0 +1,64 @@
<?php
namespace App\Http\Requests;
use Illuminate\Support\Facades\DB;
use Illuminate\Foundation\Http\FormRequest;
class CaseInsensitiveLogin extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => [
'required',
'email',
function ($attribute, $value, $fail) {
if ('sqlite' === config('database.default')) {
$user = DB::table('users')
->whereRaw('email = "' . $value . '" COLLATE NOCASE')
->first();
}
else {
$user = DB::table('users')
->where('email', $value)
->first();
}
if (!$user) {
$fail(__('validation.custom.email.exists'));
}
},
],
'password' => 'required|string',
];
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$this->merge([
'email' => strtolower($this->email),
]);
}
}

View File

@ -3,6 +3,7 @@
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
@ -26,5 +27,6 @@ public function register()
public function boot()
{
Blade::withoutComponentTags();
Schema::defaultStringLength(191);
}
}

View File

@ -49,4 +49,13 @@ public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token));
}
/**
* set Email attribute
* @param string $value
*/
public function setEmailAttribute($value)
{
$this->attributes['email'] = strtolower($value);
}
}

View File

@ -1,4 +1,15 @@
# Change log
## [2.0.1] - 2020-12-03
### Fixed
- [issue #18](https://github.com/Bubka/2FAuth/issues/18) Install using MySQL causes exception
- [issue #17](https://github.com/Bubka/2FAuth/issues/17) Capitalization of email address during login should not matter
- [issue #15](https://github.com/Bubka/2FAuth/issues/15) Applied group filter is not removed if the group is deleted
- [issue #14](https://github.com/Bubka/2FAuth/issues/14) Cache is not refreshed automatically after group changes
- Missing footer links at first start
- Missing redirection after registration
## [2.0.0] - 2020-11-29
2FAuth goes to v2.0!

View File

@ -22,7 +22,7 @@
|
*/
'version' => '2.0.0',
'version' => '2.0.1',
/*
|--------------------------------------------------------------------------

View File

@ -13,14 +13,14 @@ class AddGroupIdColumnToTwofaccountsTable extends Migration
*/
public function up()
{
Schema::enableForeignKeyConstraints();
Schema::table('twofaccounts', function (Blueprint $table) {
$table->foreignId('group_id')
$table->unsignedInteger('group_id')
->after('id')
->nullable()
->constrained()
->onDelete('set null');
$table->foreign('group_id')->references('id')->on('groups');
});
}
@ -31,11 +31,16 @@ public function up()
*/
public function down()
{
Schema::disableForeignKeyConstraints();
Schema::table('twofaccounts', function (Blueprint $table) {
// cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) {
$table->dropForeign(['group_id']);
}
}
);
Schema::table('twofaccounts', function (Blueprint $table) {
//$table->dropForeign('group_id');
$table->dropColumn('group_id');
});
}
}
}

2
public/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
{
"/js/app.js": "/js/app.js?id=05ee4b91f63a57bbb9be",
"/js/app.js": "/js/app.js?id=87f1f33515a0e89fee0d",
"/css/app.css": "/css/app.css?id=b7bb8feb3853f8d0b93e",
"/js/manifest.js": "/js/manifest.js?id=3c768977c2574a34506e",
"/js/vendor.js": "/js/vendor.js?id=d0f5711276b5b4d5a838"

View File

@ -334,7 +334,7 @@
/**
* Fetch accounts from db
*/
fetchAccounts() {
fetchAccounts(forceRefresh = false) {
let accounts = []
this.selectedAccounts = []
@ -350,11 +350,12 @@
})
})
if ( this.accounts.length > 0 && !objectEquals(accounts, this.accounts) ) {
if ( this.accounts.length > 0 && !objectEquals(accounts, this.accounts) && !forceRefresh ) {
this.$notify({ type: 'is-dark', text: '<span class="is-size-7">' + this.$t('commons.some_data_have_changed') + '</span><br /><a href="." class="button is-rounded is-warning is-small">' + this.$t('commons.reload') + '</a>', duration:-1, closeOnClick: false })
}
else if( this.accounts.length === 0 && accounts.length === 0 ) {
// No account yet, we force user to land on the start view.
this.$storage.set('accounts', this.accounts)
this.$router.push({ name: 'start' });
}
else {
@ -407,7 +408,7 @@
// we fetch the accounts again to prevent the js collection being
// desynchronize from the backend php collection
this.fetchAccounts()
this.fetchAccounts(true)
}
},
@ -424,7 +425,7 @@
// we fetch the accounts again to prevent the js collection being
// desynchronize from the backend php collection
this.fetchAccounts()
this.fetchAccounts(true)
this.fetchGroups()
this.showGroupSelector = false

View File

@ -102,6 +102,13 @@
// Remove the deleted group from the collection
this.groups = this.groups.filter(a => a.id !== id)
// Reset persisted group filter to 'All' (groupId=0)
if( parseInt(this.$root.appSettings.activeGroup) === id ) {
this.axios.post('/api/settings/options', { activeGroup: 0 }).then(response => {
this.$root.appSettings.activeGroup = 0
})
}
}
}

View File

@ -40,9 +40,9 @@
</div>
</div>
<!-- Footer -->
<vue-footer :showButtons="true" v-if="accountCount > 0">
<vue-footer :showButtons="true" >
<!-- back button -->
<p class="control">
<p class="control" v-if="accountCount > 0">
<router-link class="button is-dark is-rounded" :to="{ name: 'accounts' }" >
{{ $t('commons.back') }}
</router-link>

View File

@ -43,7 +43,7 @@
localStorage.setItem('jwt',response.data.message.token)
if (localStorage.getItem('jwt') != null){
this.$router.go('/');
this.$router.push({ name: 'accounts', params: { toRefresh: true } })
}
})
.catch(error => {

View File

@ -37,7 +37,7 @@
localStorage.setItem('jwt',response.data.message.token)
if (localStorage.getItem('jwt') != null){
this.$router.go('/');
this.$router.push({ name: 'accounts', params: { toRefresh: true } })
}
})
.catch(error => {