I have the need to send a email to a admin moderator (Tenant admin).
How do I obtain the admin email through a normal user session?
Use this code in application service
using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
{
var adminUser = _userManager
.AbpStore
.UserRepository
.GetAll()
.Single(x => x.UserName == AbpUserBase.AdminUserName && x.TenantId == AbpSession.TenantId);
SendEmailTo(adminUser.EmailAddress);
}
Related
We are evaluating Keycloak to replace Forgerock for user registration
Our current workflow provides a registration screen. On submitting the registration form, an email is sent to the user to verify their email and activate their account. The link in the email confirms the user registration before creating the user in forgerock.
My questions:
Is there a way to create the user after the email verification as a confirmation?
I have this implementation but sendVerifyEmail it is just for checking the email and basically the user can login even if he/she didn't check the email
Keycloak keycloak = KeycloakBuilder
.builder()
.serverUrl(KEYCLOAK_URL)
.realm(KEYCLOAK_REALM)
.username(KEYCLOAK_USER)
.password(KEYCLOAK_PASSWORD)
.clientId(KEYCLOAK_ADMIN_CLI)
.build();
CredentialRepresentation credential = createPasswordCredentials(userRegistrationRequest.getPassword());
UserRepresentation user = new UserRepresentation();
user.setEmail(userRegistrationRequest.getEmail());
user.setCredentials(Collections.singletonList(credential));
user.setEnabled(true);
// Get realm
RealmResource realmResource = keycloak.realm(KEYCLOAK_REALM);
UsersResource usersResource = realmResource.users();
// Create user (requires manage-users role)
Response response = usersResource.create(user);
String userId = CreatedResponseUtil.getCreatedId(response);
System.out.println("Response: " + response.getStatusInfo());
System.out.println(userId);
UserResource u = realmResource.users().get(userId);
u.sendVerifyEmail();
This is late though but you can set the user representation email verified to false when creating the user. So they won't be able to access until they verify the email.
I have 4 Separate sections as logins
Admin Login
Vendor Login
Employee Login
User Login
Admin is supposed to create all roles and permissions to these different Type of Users
How should i maintain the roles and permissions tables
Can i have only two tables such as roles and permissions to manage all these User Types
yes you have to create four tables.1 permissions,2 permission_roles,3 users and 4 user_roles table.
for define role you can use this code in login function.i hope it will help you.
if (isset($_SESSION['user']['user_id'])) {
if ($_SESSION['user']['group_slug'] == 'Admin') {
return redirect('admin/dashboard');
} else if ($_SESSION['user']['group_slug'] == 'Vendor') {
return redirect('Vendor/dashboard');
} else if ($_SESSION['user']['group_slug'] == 'Employee') {
return redirect('Employee/dashboard');
} else if ($_SESSION['user']['group_slug'] == 'User') {
return redirect('User/dashboard');
}
}
I have two user types in my registration page one is admin and another one is user,I have login page.when I logged as a admin it goes to dashboard, in dashboard I have 10 different types of components.when I logged as admin,dashboard should be display all components.but when I logged as a user dashboard should be display only 5 components(those who are related to user).I want to display these by using sessions.can you please help me how to do this by using sessions.and when I open any component in dashboard,username should be displayed on the top of the page.
public function login()
{
$data['error'] ="Invalid Login";
$this->load->view('auth/header');
if($this->input->post())
{
$user = $this->UserModel->login($this->input->post());
if(count($user)>0)
{
$array = array(
'client_id' => $user['client_id'],
'client_type_id'=>$user['client_type_id'],
'email' => $user['email'],
'password' => $user['password'],
);
$this->session->set_userdata($array);
}
else
{
$data["error_message"]="Invalid User Name and Password combination";
}
}
}
In your logging process, you can check user id and get query using id. Then you can check what are the components for logged user can access.
Get these details and put it to variable.then you can use session.
$this->session->set_userdata('set name',your variable);
and you can access this session anywhere you want.
$this->session->userdata('set name');
You can get user name via user id.
set user info in $your_var
$this->session->set_userdata('user_info', $your_var);
pass user info in array
$this->data['user_info']=$this->session->userdata['user_info'];
distroy session user info
$this->session->unset_userdata("user_info");
I have MVC website that have MVC Owin Identity login.
So user can access my website using social networks.
Now I want to allow users connect more than one social network to there accounts.
e.g.
User registered using Facebook on my website.
During registration new local user was created for him with Facebook UserLogin connection.
Now on user's profile page I want to add other socials and show already connected socials.
How to do this using MVC Owin Identity?
my solution was easy.
I just check if user is logged in and attach new social to him.
public async Task<ActionResult> Callback(string provider)
{
var externalLoginInfo = await _applicationSignInManager.AuthenticationManager.GetExternalLoginInfoAsync();
if (externalLoginInfo == null)
{
return RedirectToAction("Index", "SignIn");
}
// Check if the user with this external login provider already has a login
if (await _applicationSignInManager.UserManager.FindAsync(externalLoginInfo.Login) != null) return RedirectToAction("Index", "Social");
await _applicationSignInManager.UserManager.AddLoginAsync(HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId<long>(), externalLoginInfo.Login);
return RedirectToAction("Index", "Social");
}
I am new in ION-Auth, I want to make admin panel unique login form where admin can only login (no other user groups can allows to login here) and one for unique login form for employee group where employee can login only.
Let's say Group A is the Admin.
In the Group A controller, allow everyone to login first so you are able to check in what group that user belonged to.
Right after logging in, check if the user is an admin so he can access the Group A panel. You can check if the current user is admin by call thie is_admin metho
if($this->ion_auth->login($email, $password, $remember))
{
// It means the user has logged in. He has the correct user/pass
// Check if he is an admin
if(!$this->ion_auth->is_admin())
{ // Log out if not
$this->ion_auth->logout();
}
else
{
// Allow the access to the Group A pages
}
}
else
{
// Show the form again
}