Newer
Older
require_once($_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php');
use Mailgun\Mailgun;
class signup
{
private $username;
private $password;
private $email;
public $userid;
public $token;
function __construct($username, $password, $email)
{
$bytes = random_bytes(16);
$this->token = bin2hex($bytes);
$password = password_hash($password, PASSWORD_DEFAULT);
$this->username = $username;
$this->password = $password;
$this->email = $email;
$exist = $this->collection->findOne(['username' => $username]);
if ($exist) {
throw new Exception("User already exists");
}
$result = $this->collection->insertOne([
'username' => $username,
'password' => $password,
'email' => $email,
'token' => $this->token,
'active' => 0
]);
if ($result->getInsertedCount() !== 1) {
throw new Exception("Error inserting user");
function sendVerificationMail()
{
$config_json = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/../env.json');
$config = json_decode($config_json, true);
$token = $this->token;
$email = new \SendGrid\Mail\Mail();
$email->setFrom("noreply@selfmade.ninja", "API Course by Selfmade");
$email->setSubject("Verify your account");
$email->addTo($this->email, $this->username);
$email->addContent("text/plain", "Please verify your account at: https://api1.selfmade.ninja/verify?token=$token");
$email->addContent(
"text/html",
"<strong>Please verify your account by <a href=\"https://api1.selfmade.ninja/verify?token=$token\">clicking here</a> or open this URL manually: <a href=\"https://api1.selfmade.ninja/verify?token=$token\">https://api1.selfmade.ninja/verify?token=$token</a></strong>"
);
$sendgrid = new \SendGrid($config['email_api_key']);
try {
$response = $sendgrid->send($email);
// print $response->statusCode() . "\n";
// print_r($response->headers());
// print $response->body() . "\n";
} catch (Exception $e) {
echo 'Caught exception: ' . $e->getMessage() . "\n";
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
}
public static function mail()
{
// Instantiate the Mailgun client with your API key
$mgClient = Mailgun::create('755a963567ccf66107c080cfd1921dcb-2e68d0fb-d81394af');
$domain = "mail.sanjayy.me";
// HTML email template
$htmlTemplate = '
<table style="max-width: 600px; margin: 0 auto; background-color: #ffffff; font-family: Arial, sans-serif; color: #333333; padding: 20px; border-collapse: collapse;">
<tr>
<td style="text-align: center; padding: 10px 0;">
<img src="https://merakiui.com/images/full-logo.svg" alt="Meraki UI" style="height: 40px;">
</td>
</tr>
<tr>
<td style="padding: 20px;">
<h2 style="color: #1a202c; font-size: 24px;">Hi Olivia,</h2>
<p style="font-size: 16px; line-height: 1.5; color: #4a5568;">
Alicia has invited you to join the team on <strong>Meraki UI</strong>.
</p>
<a href="#" style="display: inline-block; margin-top: 20px; padding: 10px 20px; background-color: #3182ce; color: #ffffff; text-decoration: none; border-radius: 5px; font-size: 14px;">
Accept the invite
</a>
</td>
</tr>
<tr>
<td style="padding: 20px; text-align: center; font-size: 12px; color: #718096;">
<p>This email was sent to <a href="#" style="color: #3182ce; text-decoration: underline;">contact@merakiui.com</a>.</p>
<p>© 2024 Meraki UI. All Rights Reserved.</p>
</td>
</tr>
</table>
';
try {
// Send the email
$mgClient->messages()->send($domain, [
'from' => 'Excited User <mailgun@mail.sanjayy.me>', // Adjusted sender email to match the domain
'to' => 'email2sanjayv@gmail.com',
'subject' => 'The PHP SDK is awesome!',
'html' => $htmlTemplate // Use the HTML template
]);
echo "Email sent successfully!";
} catch (Exception $e) {
// Handle errors
echo "Error sending email: " . $e->getMessage();
public function getinsertid()
{
return $this->userid;
}
public static function verifyAccount($token)
{
$Collection = $db->auth;
$result = $Collection->findOne(['token' => $token]);
if ($result['active'] == 1) {
return "Already Verified";
} else {
$Collection->updateOne(['token' => $token], ['$set' => ['active' => 1]]);
return "Verified";
}
if ($result->getModifiedCount() == 1) {