Skip to content

Commit

Permalink
Adding updates to main
Browse files Browse the repository at this point in the history
  • Loading branch information
tnylea committed Aug 10, 2024
1 parent a36e9e7 commit e938f19
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 141 deletions.
6 changes: 3 additions & 3 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import focus from '@alpinejs/focus'
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";

window.TOCoffset = 150;
window.TOCoffset = 140;

gsap.registerPlugin(ScrollTrigger);

Expand Down Expand Up @@ -373,8 +373,8 @@ function isElementAtTopAndNotReachedNextSection(element) {
const nextSection = document.querySelector('section + section');

return (
rect.top <= TOCoffset &&
(!nextSection || rect.bottom < (nextSection.offsetTop +TOCoffset))
rect.top <= (TOCoffset+10) &&
(!nextSection || rect.bottom < (nextSection.offsetTop + (TOCoffset+10) ))
);
}

Expand Down
119 changes: 78 additions & 41 deletions content/docs/features/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ nextURL: '/docs/features/user-profiles'

# Authentication

Wave provides you with all the authentication features you need for most use-cases. Here are the login pages that you get out of the box:
Wave is built on top of <a href="https://devdojo.com/auth" target="_blank">DevDojo Auth</a>, which means your application will have all the authentication features you need for most use-cases. Be sure to refer to the <a href="https://devdojo.com/auth" target="_blank">Auth docs</a> for more advanced configurations.

- [Authentication](#authentication)
- [Auth Customizations](#auth-customizations)
- [Available Authentication Pages](#available-authentication-pages)
- [Login](#login)
- [Registration](#registration)
- [Verify Email](#verify-email)
- [Password Confirmation](#password-confirmation)
- [Password Reset/Request](#password-resetrequest)
- [Two-Factor Challenge](#two-factor-challenge)
- [Social Authentication](#social-authentication)

# Auth Customizations

Our Auth package includes a setup route that will allow you to upload a logo, change your color scheme and more. If you visit `/auth/setup` you'll see a setup page in front of you that will provide a handful of customization options.

<img src="https://cdn.devdojo.com/images/august2024/devdojo-auth-setup.jpeg" class="w-full h-auto rounded-md" />

# Available Authentication Pages

Below is a quick list of all the authentication pages you get out of the box:

- Login
- Register
Expand All @@ -19,65 +40,81 @@ Wave provides you with all the authentication features you need for most use-cas
- Password Reset
- Two-Factor Challenge

--- Previous
Let's dig into each page a little deeper.

# Authentication
### Login

Wave is built on top of the default Laravel Authentication and includes a few additional features such as email verification, forgot password, username login, and of course billing upon registration.
After a user has created an account through your application, they can login by visiting the `/auth/login` route. After successfully logging in the user will then be redirected to their dashboard.

- [Authentication](#authentication)
- [Authentication](#authentication-1)
- [Registration](#registration)
- [Login](#login)
- [Email verification](#email-verification)
- [Login with email or username](#login-with-email-or-username)
- [Forgot password](#forgot-password)
> With a fresh installation of Wave your app will have a default admin account. To use this account you can login with the following email `[email protected]` and password as `password`
---

<a name="register"></a>
### Registration

By default users will need to purchase in order to register for an account; however, you can open up free registration by visiting the admin settings `/admin/settings`, clicking on the Billing Tab, toggling off *Require Credit Card Up Front*, and save.
By default, all users can register for a free account; however, if you wanted users to be a subscriber before accessng your app, you can add the `subscribed` middleware to the dashboard and many other pages. This will restrict access to a specific page unless a user is a subscriber.

> You can use the `subscribed` middleware in place of the `auth` middleware, no need to include them both. The `subscribed` middleware will also check that the user is logged in and if not it will redirect them to the login page.
Otherwise, you may offer your users a Free minified version of your SaaS and encourage them to upgrade to a subscription plan with more advanced and bonus features.

If you wish to add some additional functionality when a user registers, you may add this to your `App\Models\User` model inside of the `boot()` method. As you can see we've already added some functionality to dynamically create a username from an email and assign the user with the default user role upon registration.

```php
protected static function boot()
{
parent::boot();

// Listen for the creating event of the model
static::creating(function ($user) {
// Check if the username attribute is empty
if (empty($user->username)) {
// Use the name to generate a slugified username
$username = Str::slug($user->name, '');
$i = 1;
while (self::where('username', $username)->exists()) {
$username = Str::slug($user->name, '') . $i;
$i++;
}
$user->username = $username;
}
});

// Listen for the created event of the model
static::created(function ($user) {
// Remove all roles
$user->syncRoles([]);
// Assign the default role
$user->assignRole( config('wave.default_user_role', 'registered') );
});
}
```

![no-cc](https://cdn.devdojo.com/images/april2021/no-cc.png)
You may modify this functionality as needed or add more functionality to it.

Now your users will be able to register for a free account.
### Verify Email

<a name="login"></a>
### Login
In order to turn on Email Verification and require your users to verify their email before accessing your application, you can toggle that setting from the Auth Settings page (`/auth/setup/settings`), toggle on the **Registration Require Email Verification**, and users will now be required to verify email before accessing your application.

After a user has created an account through your application, they can login by visiting the `/login` route. After successfully logging in the user will then be redirected to their dashboard.
<img src="https://cdn.devdojo.com/images/august2024/require-email-verification.png" class="w-full h-auto rounded-md" />

> If you have just installed Wave you can login with the default email `[email protected]` and password as `password`
Please refer to <a href="https://devdojo.com/auth/docs/config/email/" target="_blank">this documentation</a> to learn how to modify the logo in your emails.

<a name="email-verification"></a>
### Email verification

You may choose to require your users to verify their email before signing up for a free trial. To enable this you will need to visit the admin settings page at `/admin/settings`, click on the Auth tab and then toggle *Verify Email during Sign Up*
### Password Confirmation

![verify-email](https://cdn.devdojo.com/images/april2021/verify-email.png)
There may be parts of your application where you want users to confirm their password before being able to access your application. You can add the middleware name `confirm` to any page/route and the user will be required to re-enter their password.

<a name="login-options"></a>
### Login with email or username
### Password Reset/Request

Optionally you may choose to allow users to login with their email address or their username. You can also change this in the **Auth** tab of your admin settings (see screenshot above).
The password Request page allows users to enter in their email address. They will then be sent a unique password link in their email. Upon visiting that link they will be prompted to reset their password.

<a name="forgot-password"></a>
### Forgot password
### Two-Factor Challenge

Users can click on the forgot password link on the login page and they will be taken to a form where they can enter their email address.The user will then receive an email with a link to your application where they can reset their password.
You can also give your users the option of enabling Two-Factor auth to gaurantee security in their account. Learn more about <a href="https://devdojo.com/auth/docs/config/two-factor-auth/" target="_blank">setting up 2FA and enabling it for your users here</a>.

> Quick note on Email Verification and Forgot Password, your application must be configured to send email before these features can be used.
## Social Authentication

The simplest way to test emails in development mode is to use [Mailtrap](https://mailtrap.io/). You can sign up for a free account and then enter your mailtrap credentials in your `.env` file:
Setting up Social Authentication is very simple thanks to the Auth Package. From inside the `/auth/setup/providers` you can toggle the social networks you want to enable.

```html
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
```
<img src="https://cdn.devdojo.com/images/august2024/social-providers-screen.jpeg" class="w-full rounded-md border border-gray-200" />

You will also need to add the social network API keys in order to successfully enable the provider. <a href="https://devdojo.com/auth/docs/config/social-providers/" target="_blank">Learn more about that here</a>.
10 changes: 5 additions & 5 deletions content/docs/features/user-impersonations.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ Impersonating a user will allow you to login to your application acting as a spe
<a name="impersonate"></a>
## Impersonate a User

To impersonate a user you can visit your users section in your application at `/admin/users`. Find the user you want to impersonate and click on the Impersonate button.
To impersonate a user you can visit your users section inside your admin at `/admin/users`. Find the user you want to impersonate and click on the Impersonate button.

![impersonate-1.png](https://cdn.devdojo.com/images/april2021/impersonate-1.png)
<img src="https://cdn.devdojo.com/images/august2024/impersonate.png" class="w-full" />

You will now see that you are logged in as that specific user. You can click the user menu dropdown and you'll see a new **Leave Impersonation** button to exit that user account and log back in as your original admin user.
You will now see that you are logged in as that specific user. You can open the user menu and you'll see a new **Leave Impersonation** button to exit that user account and log back in as your original admin user.

![impersonate-2.png](https://cdn.devdojo.com/images/april2021/impersonate-2.png)
<img src="https://cdn.devdojo.com/images/august2024/impersonate-leave.png" class="w-full" />

Impersonations... 🍰 Piece of cake, right?
We are utilizing a popular <a href="https://github.com/404labfr/laravel-impersonate" target="_blank">Impersonation Package</a> under the hood. Be sure to check out this package readme to learn more or extend the impersonation functionality.
129 changes: 74 additions & 55 deletions content/docs/features/user-profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,95 +13,114 @@ When building your SAAS application you may want your users to provide more info

---

- [User Profile Page](#profile-page)
- [User Profile Settings](#profile-settings)
- [Custom Profile Fields](#custom-profile-fields)
- [Profile Field Types](#profile-field-types)
- [User Profiles](#user-profiles)
- [User Profile Page](#user-profile-page)
- [User Profile Settings](#user-profile-settings)
- [Custom Profile Fields](#custom-profile-fields)
- [Add Custom Profile Fields](#add-custom-profile-fields)
- [Get Profile Field Data](#get-profile-field-data)
- [Profile Field Types](#profile-field-types)

<a name="profile-page"></a>
### User Profile Page
## User Profile Page

Every user in your application will have a public profile page. The user will be able to visit `/@username` and view their profile. By default the profile page is public, which means anyone can visit that user profile.
Every user in your application will have a public profile page. The user will be able to visit `/profile/username` and view their profile. By default the profile page is public, which means anyone can visit that user profile. The profile view will show the application layout (app.blade.php) if the user is authenticated or the marketing layout (marketing.blade.php) if the user is a guest.

![admin-view](https://cdn.devdojo.com/images/april2021/admin-view.png)
<img src="https://cdn.devdojo.com/images/august2024/profile-page-user.png" class="w-full rounded-md" />

In some applications you may not have a need for a profile page. In that case, you can include the following route to your applications `routes/web.php`

```php
Route::redirect('@{username}', '/');
Route::redirect('profile/{username}', '/');
```

This will disable user profiles and redirect any user profile page back to the homepage.

> {warning} When disabling user profiles, the route must be placed after the `Wave::routes();` line.
> {warning} When disabling user profiles, the route must be placed after the `Wave::routes();` line. You may also need to run php artisan route:clear to clear the routes.
---

<a name="profile-settings"></a>
### User Profile Settings
## User Profile Settings

When a user registers for an account they will be able to edit their profile information by clicking on the settings in their user drop down.
When a user registers for an account they will be able to edit their profile information by clicking settings in their user menu.

On the user profile page the user can update their avatar, name, and email address. You will also see one more field, called `about`, this is an example of a custom profile field. Let's learn more about custom profile fields below.

![wave-profile.png](https://cdn.devdojo.com/images/april2021/wave-profile-2.png)
<img src="https://cdn.devdojo.com/images/august2024/user-settings-page.png" class="w-full rounded-md" />

---

<a name="custom-profile-fields"></a>
### Custom Profile Fields
## Custom Profile Fields

Custom profile fields allow you to add new fields in your user settings page. In the current theme you'll see a custom field called **about**. The **about** text_area can be generated with the following code:
In addition to a user name, email address and avatar you may also want to store more information about each user. You can easily do that with **Custom Profile Fields**. Let's learn more about them below.

```php
echo profile_field('text_area', 'about')
```
### Add Custom Profile Fields

> {primary} This line of code can be found in each theme, which is located at: `resources/views/themes/{theme_name}/settings/partials/profile.blade.php`.
You can easily add custom profile fields by adding them to `config/profiles.php`. If you look inside the current file in a new installation, you'll see that the contents looks like this:

The `profile_field($type, $key)` function takes 2 arguments. The **type** of field, and the **key**.
```php
<?php

return [
'fields' => [
'about' => [
'label' => 'About',
'type' => 'Textarea',
'rules' => 'required'
],
],
];
```

We can then use the **key** to reference the value of the users custom profile value. For instance to display the user's **about** value we can do the following:
Adding a new profile field is as simple as adding another item in the **fields** array. The key should be unique, in this case it's the `about` key. But let's say that you wanted to create another field that's called `occupation` and it's a TextInput field. We could add that to the `fields` array, like so:

```php
auth()->user()->profile('about');
<?php

return [
'fields' => [
'about' => [
...
],
'occupation' => [
'label' => 'What do you do for a living?',
'type' => 'TextInput',
'rules' => ''
]
],
];
```

---

The *about* field uses a *text_area* type to display a text area. In the next part we will list the different types of profile fields you can display.
Users can now save their profile with the updated fields and the data will be saved for any new data they enter. The profile data is stored inside of the **profile_key_value** table. Next, now that you can add new fields, you also need a way to retrieve the data from the custom fields.

<a name="profile-field-types"></a>
### Profile Field Types
### Get Profile Field Data

- **checkbox** - display a form check box
- **code_editor** - display a code editor (may require additional js libraries)
- **color** - display a color picker
- **date** - display a date picker (may require additional js libs)
- **file** - display a file input
- **hidden** - display a hidden input
- **image** - display an image input
- **markdown_editor** - display a markdown editor (more js required)
- **multiple_images** - display multiple image input
- **number** - display a number input
- **password** - display a password input
- **radio_btn** - display a radio button input
- **rich_text_box** - display a rich text editor (requires tinymce js)
- **select_dropdown** - display a select dropdown input
- **text** - display a textbox input
- **text_area** - display a text area input

You can use any of the profile field types above in the **first argument** of the ```profile_field($type, $key)``` function, and use any **key** (string) as the **second argument**.

Then, you can reference the value by calling:
When you want to retrieve any profile information for a particular user, you can do so with the following method:

```php
$user = User::find(1);
$user->profile($key);
auth()->user()->profile('occupation');
```

Or you can retrieve the profile value from the authenticated user like so:
This will return a string value for the authenticated user. Inside of the `profile()` method, you pass the key of the field you want to retrieve. This could be **about**, **occupation**, or any other custom field type you've added.

```php
auth()->user()->profile($key);
```
### Profile Field Types

We are utilizing the <a href="https://filamentphp.com/docs/forms" target="_blank">Filament Form Builder</a> to handle the Custom Profile Fields functionality. This means that we could use any of the field types offered in the Form Builder:

- <a href="https://filamentphp.com/docs/forms/fields/text-input" target="_blank">TextInput</a>
- <a href="https://filamentphp.com/docs/forms/fields/select" target="_blank">Select</a>
- <a href="https://filamentphp.com/docs/forms/fields/checkbox" target="_blank">Checkbox</a>
- <a href="https://filamentphp.com/docs/forms/fields/toggle" target="_blank">Toggle</a>
- <a href="https://filamentphp.com/docs/forms/fields/checkbox-list" target="_blank">CheckboxList</a>
- <a href="https://filamentphp.com/docs/forms/fields/radio" target="_blank">Radio</a>
- <a href="https://filamentphp.com/docs/forms/fields/date-time-picker" target="_blank">DateTimePicker</a>
- <a href="https://filamentphp.com/docs/forms/fields/file-upload" target="_blank">FileUpload</a>
- <a href="https://filamentphp.com/docs/forms/fields/rich-editor" target="_blank">RichEditor</a>
- <a href="https://filamentphp.com/docs/forms/fields/markdown-editor" target="_blank">MarkdownEditor</a>
- <a href="https://filamentphp.com/docs/forms/fields/tags-input" target="_blank">TagsInput</a>
- <a href="https://filamentphp.com/docs/forms/fields/textarea" target="_blank">Textarea</a>
- <a href="https://filamentphp.com/docs/forms/fields/color-picker" target="_blank">ColorPicker</a>
- <a href="https://filamentphp.com/docs/forms/fields/toggle-buttons" target="_blank">ToggleButtons</a>

You can even add a Filament plug-in and utilize that plugin custom Form Field. In this case you would need to specify the type as the full namespace to the Field. Example: `FilamentTiptapEditor\TiptapEditor`.

Be sure to check out the <a href="https://filamentphp.com/docs/forms" target="_blank">Filament Form builder</a> documentation to learn more about how you can utilize this to easily build forms in your application.
Loading

0 comments on commit e938f19

Please sign in to comment.