How I can check if an email exist in the data base in yii2 basic , I connect the database with the framework,but need help ,how to check this (its needed for the forgot password (form) )
assuming the the email you are looking for is in $email_to_check and the ActiveRecord is YourClass should be somethings like this
$model = YourClass::find()->where(['email'=> $email_to_check]);
If (isset($model)) {
// then your email exists
}
could be
$modelUser = User::find()->where(['email'=> $email_to_check]);
If (isset($modelUser)) {
// then the User with your email exists
}
Related
i have a question about fe-manager. In this extension it is possible to send a confirmation email to a admin. But it is always the same email. i like to send emails to various admins. for example: if the new user is from germany the receiving adress should be some#thing.de. if the new user is from switzerland the adress should be some#thing.ch.
any idea how to approach this?
any hints/solutions are more than welcome.
current state:
extension is created. i copied the finalCreate-Method from the AbstractController to my NewController. i changed the makeEmailArray() from:
Div::makeEmailArray(
$this->settings['new']['notifyAdmin'],
$this->settings['new']['email']['createAdminNotify']['receiver']['name']['value']
),
to:
Div::makeEmailArray('xxx#xxx.ch',
$this->settings['new']['email']['createAdminNotify']['receiver']['name']['value']
),
the ts setup.txt file is located in femanager_extended/Configuration/TypoScript/setup.txt
and contains the following code:
config.tx_extbase.objects {
In2\Femanager\Controller\NewController.className = Lbaumann\FemanagerExtended\Controller\NewController
}
is this the right approach?
There is no TypoScriptConfig for this behaiviour, but you can easily override the ControllerMethod and extend it with your needs.
Create your own extension like Vender "Vendor" (company/customername) and key "femanager_extended" with the extension_builder.
femanager_extended/Classes/Controller/NewController.php
<?php
namespace Vendor\FemanagerExtended\Controller;
class NewController extends \In2\Femanager\Controller\NewController
{
public function finalCreate($user, $action, $redirectByActionName, $login = true)
{
// own business logic
// replace the first Div::makeEmailArray...
// with your selected Admin-email-address
// see parent::finalCreate($user, $action, $redirectByActionName, $login);
}
}
femanager_extened/ext_typoscript_setup.txt
config.tx_extbase.objects {
In2\Femanager\Controller\NewController.className = Vendor\FemanagerExtended\Controller\NewController
}
I hope this will help you and i don´t forgot any settings.
I'm 11 and I'm making a chat site for me and my friends. I'm using MYSQLi to handle the database things, and I'm kinda new to it. I always used normal mysql.
Oh! And if you can share a link to a mysqli tutorial, it would be great :)
Well here's my config file
<?PHP
define("HOST", "localhost"); define("USER", "root"); define("PASSWORD", "****"); define("DATABASE", "secure_login");
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
?>
The database is secure_login, then I have a table called members, and then a column named email in that table.
I included this to a file (register.php) where I have to check if the email exists or not. And if it exists, redirect to home.
If you guys can help me it would be cool!!! I hope to finish this soon :)
I'd start with reading the MySQLi documentation at http://php.net/manual/en/book.mysqli.php, in specific the methods related to the class. If you are in need of a tutorial I would suggest to search on Google, there are loads of tutorials on the web.
As for your question, something like this should work:
$query = "SELECT email FROM members WHERE USER = ? AND PASS = ?";
if ($stmt = $mysqli->prepare($query)){
// Bind the parameters, these are the ?'s in the query.
$stmt->bind_param("ss", $username, sha1($password));
// Execute the statement
if($stmt->execute()){
// get the results from the executed query
$stmt->store_result();
$email_res= "";
// This stores the value of the emailaddres inside $email_res
$stmt->bind_result($email_res);
$stmt->fetch();
// There is a result
if ($stmt->num_rows == 1){
// Validate the emailadres here, check the PHP function filter_var()
}
else {
// Not a valid email
}
}
else {
printf("Execute error: %s", $stmt->error);
}
}
else {
printf("Prepared Statement Error: %s\n", $mysqli->error);
}
}
I hope this helps
there is a custom login form that should give users access to certain contents on the same page. That works so far with Users stored as Members in the SS database and I was checking after Login if the user has permissions like this in the Page Class:
function isAllowed() {
if (Member::currentUser()) {
$PresseGroup = DataObject::get_one('Group', "Code = 'presse'");
$AdminGroup = DataObject::get_one('Group', "Code = 'administrators'");
if (Member::currentUser()->inGroup($PresseGroup->ID) || Member::currentUser()->inGroup($AdminGroup->ID)) {
return true;
}
}
}
in the Template I just did this:
<% if isAllowed %>
SecretContent
<% end_if %>
OK so far, but now the users will not be stored in the silverstripe database - they are stored on a another server.
On that external server is running a little php script accepting the username and password. The script just returns user has permission: true or false.
I´m calling that script via cURL.
I planned to overwrite the dologin Function of MemberLoginForm. Now I just wonder how to check after Login that the User got the permission and display the contents... I tried to set a variable in the controller of the Page or should I set a session Variable? Thats my attempt (CustomLoginForm extends MemberLoginForm):
public function dologin($data) {
if(userHasPermission("user1", "pw")==true){
$this->controller->Test("test");
}
$link = $this->controller->Link();
$this->performLogin($data);
$this->controller->redirect($link);
}
I hope someone can help me with that - I know very specific - problem.
Many thanx,
Florian
In SilverStripe you can create a custom authenticator, which means users can log in on your website with accounts that are stored somewhere else, or even just a hard coded user and password.
You can check out the OpenID Authentication Module for example code on how to do it
But for your task this might even be to complex of a solution, how about after login just do something like Session::set('isAllowed', true); and to check if the user is allowed to view:
function isAllowed() {
if (Member::currentUser()) {
$PresseGroup = DataObject::get_one('Group', "Code = 'presse'");
$AdminGroup = DataObject::get_one('Group', "Code = 'administrators'");
if (Member::currentUser()->inGroup($PresseGroup->ID) || Member::currentUser()->inGroup($AdminGroup->ID)) {
return true;
}
}
// if Member::currentUser() is not allowed to view,
// return the session, which is either set to true or it returns null if not set
return Session::get('isAllowed');
}
I am attempting to make an authentication plugin. JUser::getInstance() takes one input, and it is supposed to be the id. Is there any way to get an instance of a User using some other indentifier? such as username, email etc.
Probably there isnt any such method. But yes if you are sure that username or email are unique then you can modify your file user.php in libraries/joomla/user/ and add a method there.
getInstanceByEmail($email)
{
$query = "select id from jos_users where email=".email;
// use the code to get the id;
return getInstance($id);
} // this is just a sample code of how it can be achieved
Since Joomla's own authentication is done by checking the user's username (and password of course), it has to be unique. And yes you can do something like what #Rixius suggested.
Here's my version:
// Get a database object
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id, password');
$query->from('#__users');
$query->where('username=' . $db->Quote($credentials['username']));
$db->setQuery($query);
$result = $db->loadObject();
$user = JFactory::getUser();
if ($result)
{
$user = JUser::getInstance($result->id);
}
I'm using Zend_Auth with a "Database Table Authentication". What I want to do is allow the user to login with either a username or email address as the "identityColumn". How would I allow both. I'm stuck.
Extend and implement your own Auth Adapter and use query like "WHERE username = ? or email = ?" to get Auth result :)
Authenticate twice (if needed) with 2 different Zend_Auth_Adapter_DbTable objects and add some logic to determine if the login is username or email by guessing if what type of login user provided so that you save one query for most of the cases.
I know this is not the cleanest Zend_Auth implementation, but it works. The only problem comes if someone registers with an different email address as a username, but of course you can prevent this in your registration form. Hope it helps.
// if the entered value validates as an email address then use the 'email' field
// if not, use the 'username' field
$validator = new Zend_Validate_EmailAddress();
if ($validator->isValid($form->getValue('password'))) {
$identityField = 'email';
} else {
$identityField = 'username';
}
$authAdapter = new Zend_Auth_Adapter_DbTable(
$dbAdapter,
'users',
$identityField,
'password',
'SHA1(?)'
);
$authAdapter->setIdentity($form->getValue('username'))
->setCredential($form->getValue('password'));