Skip to content

Commit

Permalink
fix: forgot pass notification
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Jul 6, 2023
1 parent 23e052e commit 037cbcf
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 52 deletions.
74 changes: 37 additions & 37 deletions app/GraphQL/Ecosystem/Mutations/Auth/AuthManagementMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,6 @@ class AuthManagementMutation
use TokenTrait;
use AuthTrait;

/**
* @param array $args
*
* @throws \Exception
*/
public function forgot(
mixed $rootValue,
array $request,
GraphQLContext $context = null,
ResolveInfo $resolveInfo
): bool {
$user = new ForgotPasswordService();

$registeredUser = $user->forgot($request['data']['email']);
$tokenResponse = $registeredUser->createToken('kanvas-login')->toArray();

$request = request();

return true;
}

/**
* Reset user password.
*/
public function reset(
mixed $rootValue,
array $request,
GraphQLContext $context = null,
ResolveInfo $resolveInfo
): bool {
$user = new ForgotPasswordService();

$user->reset($request['data']['new_password'], $request['data']['hash_key']);

return true;
}

/**
* @param array $args
*
Expand Down Expand Up @@ -193,4 +156,41 @@ public function socialLogin(mixed $root, array $req): array

return $tokenResponse;
}

/**
* @param array $args
*
* @throws \Exception
*/
public function forgot(
mixed $rootValue,
array $request,
GraphQLContext $context = null,
ResolveInfo $resolveInfo
): bool {
$user = new ForgotPasswordService();

$registeredUser = $user->forgot($request['data']['email']);
$tokenResponse = $registeredUser->createToken('kanvas-login')->toArray();

$request = request();

return true;
}

/**
* Reset user password.
*/
public function reset(
mixed $rootValue,
array $request,
GraphQLContext $context = null,
ResolveInfo $resolveInfo
): bool {
$user = new ForgotPasswordService();

$user->reset($request['data']['new_password'], $request['data']['hash_key']);

return true;
}
}
14 changes: 5 additions & 9 deletions graphql/schemas/Ecosystem/user.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,23 @@ input UpdateUserInput {
address_1: String
address_2: String
zip_code: Int
city_id: Int
@rules(apply: ["exists:Kanvas\\Locations\\Models\\Cities,id"])
state_id: Int
@rules(apply: ["exists:Kanvas\\Locations\\Models\\States,id"])
city_id: Int @rules(apply: ["exists:Kanvas\\Locations\\Models\\Cities,id"])
state_id: Int @rules(apply: ["exists:Kanvas\\Locations\\Models\\States,id"])
country_id: Int
@rules(
apply: ["exists:Kanvas\\Locations\\Models\\Countries,id"]
)
@rules(apply: ["exists:Kanvas\\Locations\\Models\\Countries,id"])
}

extend type Mutation {
login(data: LoginInput!): TokenResponse!
@field(
resolver: "App\\GraphQL\\Ecosystem\\Mutations\\Auth\\AuthManagementMutation@loginMutation"
)
logout: Boolean!
logout: Boolean!
@guard
@field(
resolver: "App\\GraphQL\\Ecosystem\\Mutations\\Auth\\AuthManagementMutation@logout"
)
logoutFromAllDevices: Boolean!
logoutFromAllDevices: Boolean!
@guard
@field(
resolver: "App\\GraphQL\\Ecosystem\\Mutations\\Auth\\AuthManagementMutation@logoutFromAllDevices"
Expand Down
8 changes: 5 additions & 3 deletions src/Kanvas/Notifications/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Notification extends LaravelNotification implements EmailInterfaces, Shoul
protected ?UserInterface $toUser = null;

public array $channels = [
'mail'
'mail',
];

public function __construct(Model $entity)
Expand All @@ -44,7 +44,6 @@ public function __construct(Model $entity)
$this->data = [
'entity' => $this->entity,
'app' => $this->app,
'user' => $this->toUser ? $this->toUser : null,
];
}

Expand Down Expand Up @@ -72,6 +71,10 @@ public function via(object $notifiable): array
$channels = array_values($enabledChannels);
}

//set the user
$this->data['user'] = $notifiable;
$this->toUser = $notifiable;

return [
KanvasDatabaseChannel::class,
...$channels,
Expand All @@ -87,7 +90,6 @@ public function toMail($notifiable): ?MailMessage
{
$fromEmail = $this->app->get('from_email_address') ?? config('mail.from.address');
$fromName = $this->app->get('from_email_name') ?? config('mail.from.name');
$this->toUser = $notifiable;

return (new MailMessage())
->from($fromEmail, $fromName)
Expand Down
2 changes: 1 addition & 1 deletion src/Kanvas/Notifications/Templates/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function getData(): array
{
return [
...parent::getData(),
'resetUrl' => $this->app->url . '/users/reset-password/' . $this->toUser->user_activation_forgot,
'resetUrl' => $this->app->get('url') . '/reset-password/' . $this->toUser->getAppProfile($this->app)->user_activation_forgot,
];
}
}
2 changes: 0 additions & 2 deletions src/Kanvas/Users/Models/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ public function resetPassword(string $newPassword, AppInterface $app): bool
{
$user = $this->getAppProfile($app);
$user->password = Hash::make($newPassword);
$user->saveOrFail();

$user->user_activation_forgot = '';
$user->saveOrFail();

Expand Down

0 comments on commit 037cbcf

Please sign in to comment.