I am using Code Igniter 2.0.3.
I am having various roles in my application and I want to set up various email configurations depending upon those roles.
As per this we can set up the configurations in config/email.php for one account, but I want to set up multiple accounts, so that depending upon the role I just call the role at run time and my settings are initialized automatically.
Sample code could be
$config['first_setting']['protocol'] = 'sendmail';
$config['first_setting']['mailpath'] = '/usr/sbin/sendmail';
$config['first_setting']['charset'] = 'iso-8859-1';
$config['first_setting']['smtp_user'] = 'j#j.j';
$config['first_setting']['wordwrap'] = TRUE;
$this->email->initialize($config['first_seeting']);
Gracias.
You don't need to use the config file to set the email class up.
When you "call the role" depending on the role it can set those settings at runtime with its own settings based on role data.
for example you'll have something like this:
function login(){
//do login stuff
//email settings for this user / role
$this->load->library('email'); //ensure its loaded
$conf['protocol'] = 'sendmail';
$conf['mailpath'] = '/usr/sbin/sendmail';
$conf['charset'] = 'iso-8859-1';
$conf['smtp_user'] = $this->session->userdata('email'); //user/role specific settings
$conf['wordwrap'] = TRUE;
$this->email->initialize($conf);
}
From there on out when you use the email class it will be sent using these settings. (provided you don't overwrite them latter)
Related
In my project I have lot of endpoint views (APIViews, ViewSets). For all of them now I set permissions, some of them are default (e.g. AllowAny) and some are custom created:
permission_classes = (IsUserHaveSomePermission,)
Now I want to implement some flexible system, that will allow me to specify set of allowed endpoints for each user, for example:
On front-end I want to select some user and have a list of checkboxes that correspond to project's endpoints.
This is just an utopian solution, some details may be changed, but the main question is to how make something similar so that admins can basically dynamically change list of allowed endpoints/views for user?
thanks in advance
This solution can be implemented by storing if the user has permission to access the current request method and request path.
Create a new db model for storing the user, request method and request path. Lets say the name of the model is RequestPermission
Instead of the path you can store a constant representing the url so that you have the flexibility of editing the path later on. This constant can be the url name which is supported by django.
class RequestPermission(models.Model):
user = user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='request_permissions')
method = models.CharField(max_length=10)
path_name = models.CharField(max_length=200)
create a custom permission class:
class IsUserResuestAllowed(permissions.BasePermission):
def has_permission(self, request, view):
user = request.user
# you can choose how to get the path_name from the path
path_name = get_path_name(request.path)
return RequestPermission.objects.filter(user=user, method=request.method, path_name=path_name).exists()
Now you can use this class as the default permission class in rest framework settings or use it per view.
I'm trying to set a cron-job for sending mail attachments from my cpanel server.
I found that Mutt is a great option.
However, I'm having difficulty due to this one error that keeps occurring again and again.
Whenever I try sending a mail I get this:
SASL authentication failed.
Could not send the message.
The following is my .muttrc file.
set from = USERNAME#gmail.com
set realname = "NAME"
#set smtp_url = smtp://USERNAME#gmail.com:587/
set smtp_url = "smtps://USERNAME#smtp.gmail.com:465/"
set smtp_pass = PASS
set imap_user = USERNAME#gmail.com
set imap_pass = PASS
set folder = imaps://imap.gmail.com:993
set spoolfile = imaps://imap.gmail.com/INBOX
set header_cache = ~/.mutt/cache/headers
set message_cachedir = ~/.mutt/cache/bodies
set certificate_file = ~/.mutt/certificates
# Etc
set mail_check = 100
set move = no
set imap_keepalive = 900
set sort = threads
set editor = "vim"
#source ~/.mutt/gpg.rc
set ssl_starttls=no
set ssl_force_tls=yes
set smtp_authenticators = "login"
set ssl_verify_host = no
set ssl_verify_dates = no
This may take a long time (probably won't be solvable) and there might not be many people with this problem. But I feel that this thread might help others in the future
I've installed gnutils-bin and openssl
which gnutls-bin
/usr/bin/which: no gnutls-bin in (/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/usr/local/python3.6/bin:/usr/local/bin:/home/covid/.local/bin:/home/USERNAME/bin)
which openssl
/usr/bin/openssl
I ran into the same thing, I had to change my muttrc config so that set realname='name' was exactly the same as the Name in that is in gmails Personal Info for the account.
Also in Gmails Security "Less secure app access" needs to be set to ON
Just a quick update, according to google support for security reasons "Allow less secure apps" is no longer availabe (see here), however, there is still a workaround, please see below:
You might need to first enable MFA and then in your google account setting, under "Sign in to Google" select "App Passwords" (check out this google article if you don't see this option on your google account: 185833)
Basically, I'm using the accounts-base package on meteor and on meteor startup, I set up what template the server should use for the password recovery mail, email confirmation mail, etc.
For example, in my server/startup.js on meteor startup I do many things like :
Accounts.urls.verifyEmail = function (token) {
return Meteor.absoluteUrl(`verify-email/${token}`);
};
Accounts.emailTemplates.verifyEmail.html = function (user, url) {
return EmailService.render.email_verification(user, url);
};
The problem is that my app is hosted on multiple host names like company1.domain.com, company2.domain.com, company3.domain.com and if a client wants to reset his password from company1.domain.com, the recovery url provided should be company1.domain.com/recovery.
If another client tried to connect on company2.domain.com, then the recovery url should be company2.domain.com.
From my understanding, this is not really achievable because the method used by the Accounts Package is "Meteor.absoluteUrl()", which returns the server ROOT_URL variable (a single one for the server).
On the client-side, I do many things based on the window.location.href but I cannot seem, when trying to reset a password or when trying to confirm an email address, to send this url to the server.
I'm trying to find a way to dynamically generate the url depending on the host where the client is making the request from, but since the url is generated server-side, I cannot find an elegent way to do so. I'm thinking I could probably call a meteor server method right before trying to reset a password or create an account and dynamically set the ROOT_URL variable there, but that seems unsafe and risky because two people could easily try to reset in the same timeframe and potentially screw things up, or people could abuse it.
Isn't there any way to tell the server, from the client side, that the URL I want generated for the current email has to be the client current's location ? I would love to be able to override some functions from the account-base meteor package and achieve something like :
Accounts.urls.verifyEmail = function (token, clientHost) {
return `${clientHost}/verify-email/${token}`;
};
Accounts.emailTemplates.verifyEmail.html = function (user, url) {
return EmailService.render.email_verification(user, url);
};
But I'm not sure if that's possible, I don't have any real experience when it comes to overriding "behind the scene" functionalities from base packages, I like everything about what is happening EXCEPT that the url generated is always the same.
Okay so I managed to find a way to achieve what I was looking for, it's a bit hack-ish, but hey..
Basically, useraccounts has a feature where any hidden input in the register at-form will be added to the user profile. So I add an hidden field to store the user current location.
AccountsTemplates.addField({
_id: 'signup_location',
type: 'hidden',
});
When the template is rendered, I fill in this hidden input with jQuery.
Template.Register.onRendered(() => {
this.$('#at-field-signup_location').val(window.location.href);
});
And then, when I'm actually sending the emailVerification email, I can look up this value if it is available.
Accounts.urls.verifyEmail = function (token) {
return Meteor.absoluteUrl(`verify-email/${token}`);
};
Accounts.emailTemplates.verifyEmail.html = function (user, url) {
const signupLocation = user.profile.signup_location;
if (signupLocation) {
let newUrl = url.substring(url.indexOf('verify-email'));
newUrl = `${signupLocation}/${newUrl}`;
return EmailService.render.email_verification(user, newUrl);
}
return EmailService.render.email_verification(user, url);
};
So this fixes it for the signUp flow, I may use the a similar concept for resetPassword and resendVerificationUrl since the signupLocation is now in the user profile.
You should probably keep an array of every subdomains in your settings and keep the id of the corresponding one in the user profile, so if your domain changes in the future then the reference will still valid and consistent.
I am not able to add a new user to the "confluence-users" group. I am able to add a new user to the database, and when I am trying to add him to the group, it says
"User [Anonymous] does not have the required privileges."
I guess, it needs admin privileges to add a user to group and how can I specify it while adding a user to group. I am using confluence 3.5 api and pls let me know how to achieve this.
My code looks like below..
UserAccessor userAccessor = (UserAccessor)ContainerManager.getInstance().getContainerContext().getComponent("userAccessor");
Group group = userAccessor.getGroup(UserAccessor.GROUP_CONFLUENCE_USERS);
DefaultUser defaultUser = new DefaultUser(username,fullname,email);
User newuser = userAccessor.createUser(defaultUser,Credential.unencrypted(password));
userAccessor.addMembership(group,newuser);
Try this:
UserManager userManager = (UserManager) ContainerManager.getComponent("userManager");
userManager.createUser(newUser, Credential.NONE);
groupManager.addMembership(group, user);
You'll need to inject the GroupManager in your class.
I have two tables : Users & Profiles. A user has one profile (1:1), a profile can be affected to many users, each profile has many modules, each module has many actions.
I'm sending this object from an asmx to a aspx page using a direct service call.
I got an error because of lazy loading ... so I disabled the lazy loading.
this.Configuration.LazyLoadingEnabled = false;
this works fine, I got my user, with the profile null.
To build the menu tree I have to retrieve the profile. I included It :
User user = new User();
using (cduContext db = new cduContext())
{
// get the user
string encryptedPassword = Encryption.Encrypt(password);
user = (from u in db.Users
where u.UserName.Equals(login) &&
u.Password.Equals(encryptedPassword)
select u).FirstOrDefault();
// Include the users profile
user = db.Users.Include("Profile").FirstOrDefault();
}
return user;
I got this error in the javascript call function :
A circular reference was detected while serializing an object of type 'CDU.Entities.Models.User'.
When I made a quick watch on the user object, in asmx ( before sending it ) , I found, that the profile has included the list of the users who had this pofile, each user has his profile loaded ... etc
Any idea please ?
Note, your code should look like this:
using (cduContext db = new cduContext())
{
// get the user
string encryptedPassword = Encryption.Encrypt(password);
var user = from u in db.Users
where u.UserName.Equals(login) &&
u.Password.Equals(encryptedPassword)
select u;
// Include the users profile
return user.Include("Profile").FirstOrDefault();
}
In your code, you were throwing away the first query by overwriting it with the second. And there was no valid reason to create a blank user.
To address your problem, you're going to have make a decision on what you don't want to serialize. In your case, you probably don't want to serialize Profile.Users
You don't mention what serializer you're using. I'm assuming you're using the DataContract serializer?
EDIT:
You would mark your Profile.Users object with the [IgnoreDataMember] Attribute.