Skip to content

Commit

Permalink
Merge pull request #49 from Kovah/dev
Browse files Browse the repository at this point in the history
v0.0.15
  • Loading branch information
Kovah committed Apr 28, 2019
2 parents 9cb4f25 + 578e10a commit cb59731
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 102 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -70,7 +70,8 @@ want to use for the application.

#### 2. Modify the .env.docker file

Now open the `.env.docker` file and follow the instructions inside the file. All needed variables you have to configure
Rename the `.env.docker` file to `.env`.
Now open the `.env` file and follow the instructions inside the file. All needed variables you have to configure
are marked accordingly.

#### 3. Modify the nginx.conf file (optional)
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Controllers/App/UserSettingsController.php
Expand Up @@ -4,6 +4,7 @@

use App\Helper\LinkAce;
use App\Http\Controllers\Controller;
use App\Http\Requests\UserAccountUpdateRequest;
use App\Http\Requests\UserSettingsUpdateRequest;
use App\Models\Setting;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -33,15 +34,15 @@ public function getUserSettings()
}

/**
* @param UserSettingsUpdateRequest $request
* @param UserAccountUpdateRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function saveAccountSettings(UserSettingsUpdateRequest $request)
public function saveAccountSettings(UserAccountUpdateRequest $request)
{
$user = auth()->user();

$user->update($request->only([
'username',
'name',
'email',
]));

Expand Down Expand Up @@ -97,7 +98,7 @@ public function changeUserPassword(Request $request)
$data = $request->all();

// Validate the request by checking if the old password is currect
$data['old_password'] = Auth::attempt([$current_user->email, $data['old_password']]);
$data['old_password'] = Auth::attempt(['email' => $current_user->email, 'password' => $data['old_password']]);

$validator = Validator::make($data, [
'old_password' => 'accepted',
Expand Down
53 changes: 53 additions & 0 deletions app/Http/Requests/UserAccountUpdateRequest.php
@@ -0,0 +1,53 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;

class UserAccountUpdateRequest extends FormRequest
{
/** @var bool */
private $validate_username = false;

/** @var bool */
private $validate_email = false;

/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(Request $request)
{
// Validate the username if it was changed
if ($request->get('username') !== auth()->user()->name) {
$this->validate_username = true;
}

// Validate the email address if it was changed
if ($request->get('email') !== auth()->user()->email) {
$this->validate_email = true;
}

return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
if ($this->validate_username) {
$rules['username'] = 'unique:users,name';
}

if ($this->validate_email) {
$rules['email'] = 'unique:users,email';
}

return $rules;
}
}
29 changes: 2 additions & 27 deletions app/Http/Requests/UserSettingsUpdateRequest.php
Expand Up @@ -7,29 +7,14 @@

class UserSettingsUpdateRequest extends FormRequest
{
/** @var bool */
private $validate_username = false;

/** @var bool */
private $validate_email = false;

/**
* Determine if the user is authorized to make this request.
*
* @param Request $request
* @return bool
*/
public function authorize(Request $request)
{
// Validate the username if it was changed
if ($request->get('username') !== auth()->user()->name) {
$this->validate_username = true;
}

// Validate the email address if it was changed
if ($request->get('email') !== auth()->user()->email) {
$this->validate_email = true;
}

return true;
}

Expand All @@ -40,18 +25,8 @@ public function authorize(Request $request)
*/
public function rules()
{
$rules = [
return [
'timezone' => 'required',
];

if ($this->validate_username) {
$rules['username'] = 'unique:users,name';
}

if ($this->validate_email) {
$rules['email'] = 'unique:users,email';
}

return $rules;
}
}
14 changes: 14 additions & 0 deletions app/Models/Link.php
Expand Up @@ -117,6 +117,20 @@ public function notes()
| METHODS
*/

/**
* Display the short URL if it's longer than 60 characters
*
* @return string
*/
public function shortUrl()
{
if (mb_strlen($this->url) > 60) {
return substr($this->url, 0, 60) . '...';
}

return $this->url;
}

/**
* @return null|string
*/
Expand Down
14 changes: 7 additions & 7 deletions docker-compose.production.yml
Expand Up @@ -14,7 +14,7 @@ services:
- MARIADB_PASSWORD=${DB_PASSWORD}
- MARIADB_DATABASE=${DB_DATABASE}
env_file:
- ./.env.docker
- ./.env
volumes:
- db:/bitnami

Expand All @@ -25,23 +25,23 @@ services:
restart: always
volumes:
- linkace_app:/app
- ./.env.docker:/app/.env:ro
- ./.env:/app/.env:ro

# --- nginx
nginx:
container_name: "linkace-nginx"
image: bitnami/nginx:latest
restart: always
ports:
- "127.0.0.1:80:8085"
#- "127.0.0.1:443:8085"
- "0.0.0.0:80:8085"
#- "0.0.0.0:443:8085"
depends_on:
- php
env_file:
- ./.env.docker
- ./.env
volumes:
- linkace_app:/app
- nginx.conf:/opt/bitnami/nginx/conf/vhosts/site.conf:ro
- ./nginx.conf:/opt/bitnami/nginx/conf/vhosts/site.conf:ro
#- /path/to/ssl/certificates:/bitnami/nginx/conf/bitnami/certs

# --- Redis
Expand All @@ -50,7 +50,7 @@ services:
image: bitnami/redis:latest
restart: always
env_file:
- ./.env.docker
- ./.env
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "linkace",
"version": "0.0.14",
"version": "0.0.15",
"description": "A small, selfhosted bookmark manager with advanced features, built with Laravel and Docker",
"homepage": "https://github.com/Kovah/LinkAce",
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions resources/docker/dockerfiles/release.Dockerfile
Expand Up @@ -56,4 +56,7 @@ COPY --from=npm_builder /srv/public /app/public
# Cleanup dev stuff from final image
RUN rm -rf /app/node_modules

# Set correct permissions for the storage directory
RUN chmod 0777 -R /app/storage

WORKDIR /app
2 changes: 2 additions & 0 deletions resources/lang/en/linkace.php
Expand Up @@ -39,4 +39,6 @@

'bookmarklet_close' => 'This bookmarklet window automatically closes in <span class="bm-timer">5</span> seconds.',
'open_linkace' => 'Open LinkAce',

'demo_login_hint' => 'You can login right away. Please notice that this demo will be reset every 2 hours.',
];
Expand Up @@ -11,12 +11,12 @@
<label for="username">
@lang('user.username')
</label>
<input type="text" name="username" id="username" required
class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}"
placeholder="@lang('user.username')" value="{{ old('username') ?: $user->name }}">
@if ($errors->has('username'))
<input type="text" name="name" id="name" required
class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}"
placeholder="@lang('user.username')" value="{{ old('name') ?: $user->name }}">
@if ($errors->has('name'))
<p class="invalid-feedback" role="alert">
{{ $errors->first('username') }}
{{ $errors->first('name') }}
</p>
@endif
</div>
Expand All @@ -26,6 +26,7 @@ class="form-control{{ $errors->has('username') ? ' is-invalid' : '' }}"
@lang('user.email')
</label>
<input type="text" name="email" id="email" required
@if(env('APP_DEMO')) disabled @endif
class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}"
placeholder="@lang('user.email')" value="{{ old('email') ?: $user->email }}">
@if ($errors->has('email'))
Expand Down
87 changes: 45 additions & 42 deletions resources/views/actions/settings/partials/change-pw.blade.php
@@ -1,44 +1,47 @@
<div class="card mt-4">
<div class="card-header">
@lang('settings.change_password')
</div>
<div class="card-body">

<form action="{{ route('change-user-password') }}" method="POST">
@csrf

<div class="form-group">
<label for="old_password">
@lang('settings.old_password')
</label>
<input type="text" name="old_password" id="old_password" required
class="form-control{{ $errors->has('old_password') ? ' is-invalid' : '' }}"
placeholder="@lang('settings.old_password')">
</div>

<div class="form-group">
<label for="new_password">
@lang('settings.new_password')
</label>
<input type="text" name="new_password" id="new_password" required
class="form-control{{ $errors->has('new_password') ? ' is-invalid' : '' }}"
placeholder="@lang('settings.new_password')">
</div>

<div class="form-group">
<label for="new_password_confirmation">
@lang('settings.new_password2')
</label>
<input type="text" name="new_password_confirmation" id="new_password_confirmation" required
class="form-control{{ $errors->has('new_password_confirmation') ? ' is-invalid' : '' }}"
placeholder="@lang('settings.new_password2')">
</div>

<button type="submit" class="btn btn-primary">
<i class="fa fa-key fa-mr"></i> @lang('settings.change_password')
</button>

</form>
@if(!env('APP_DEMO', false))
<div class="card mt-4">
<div class="card-header">
@lang('settings.change_password')
</div>
<div class="card-body">

<form action="{{ route('change-user-password') }}" method="POST">
@csrf

<div class="form-group">
<label for="old_password">
@lang('settings.old_password')
</label>
<input type="password" name="old_password" id="old_password" required
class="form-control{{ $errors->has('old_password') ? ' is-invalid' : '' }}"
placeholder="@lang('settings.old_password')">
</div>

<div class="form-group">
<label for="new_password">
@lang('settings.new_password')
</label>
<input type="password" name="new_password" id="new_password" required
class="form-control{{ $errors->has('new_password') ? ' is-invalid' : '' }}"
placeholder="@lang('settings.new_password')">
</div>

<div class="form-group">
<label for="new_password_confirmation">
@lang('settings.new_password2')
</label>
<input type="password" name="new_password_confirmation" id="new_password_confirmation" required
class="form-control{{ $errors->has('new_password_confirmation') ? ' is-invalid' : '' }}"
placeholder="@lang('settings.new_password2')">
</div>

<button type="submit" class="btn btn-primary">
<i class="fa fa-key fa-mr"></i> @lang('settings.change_password')
</button>

</form>

</div>
</div>
</div>
@endif

9 changes: 7 additions & 2 deletions resources/views/auth/login.blade.php
Expand Up @@ -5,6 +5,10 @@
<div class="row justify-content-center">
<div class="col-12 col-md-8">

@if(env('APP_DEMO', false))
<div class="alert alert-info small">@lang('linkace.demo_login_hint')</div>
@endif

<div class="card">
<div class="card-header">
@lang('linkace.login')
Expand All @@ -21,7 +25,7 @@
</div>
</div>
<input type="email" name="email" id="email" class="form-control"
value="{{ old('email') }}"
value="{{ env('APP_DEMO', false) ? 'linkace@example.com' : old('email') }}"
placeholder="@lang('linkace.email')" aria-label="@lang('linkace.email')" required
autofocus>
</div>
Expand All @@ -41,7 +45,8 @@
</div>
</div>
<input type="password" name="password" id="password" class="form-control"
placeholder="@lang('linkace.password')" aria-label="@lang('linkace.password')">
@if(env('APP_DEMO', false)) value="demopassword" @endif
placeholder="@lang('linkace.password')" aria-label="@lang('linkace.password')">
</div>
@if ($errors->has('password'))
<p class="invalid-feedback" role="alert">
Expand Down

0 comments on commit cb59731

Please sign in to comment.