How to determine if a profile already has a password set within a Journy Decision node - kademi

I would like to set up a decision in a Journey that determines if the current profile has a password set.
Using Decision node and selecting Rules, there does not appear to be an option to look up a password column.
Here's my journey.
https://spinsurance.admin.kademi.com.au/funnels/email-new-policy-holder-users/version1/#journeyBuilder-tab

One option is to create a custom journey field. As an example, Add the code to a custom app under /APP-INF/:
controllerMappingList.addTextJourneyField('profileHasProfile', 'Profile Has Password', 'checkProfilePassword');
function checkProfilePassword(profile) {
var userResource = applications.userApp.findUserResource(profile);
if( formatter.isNotNull(userResource) ){
return userResource.isHasPassword();
}
return 'false';
}
Then you can use that field with an equals operator

Normally journeys need to take action when the user sets a password, or doesnt after a timeout. You can do that with the "Created credentials" goal, rather then a decision node
The previous answers are correct if you do actually need a decision

Related

How to check whether specific value exists in request in laravel?

I'm stuck in checking whether a specific value exists in the request. I'm doing like this,
foreach ($variant->sale_channels as $v_sale_channel) {
$v_sale_channel->enabled = ($request->has('sale_channels_enabled.'.$v_sale_channel->sale_channel_id)) ? true : false;
$variant_sale_channels[] = $v_sale_channel;
}
Am I doing it wrong $request->has('sale_channels_enabled.'.$v_sale_channel->sale_channel_id)
sale_channels_enabled is an array which contains only sale channel id's. I want to check weather a specific value exists in that array or not.
You can use in_array():
if (in_array($v_sale_channel->sale_channel_id, $request->sale_channels_enabled))

laravel update shouldn't do anything if no value changed

If I open a form to edit and without changing any value just hit Submit button to update, it updates the row in the table i.e. it changes the updated_at time and even executes some code in bootXXXX(static::saving(function($model) {}) function.
I do not want that to happen.
How can I find If user changed nothing and its a blank submit button hit?
Of course before update I can fetch the current values and compare them with input $request->all() and decide to update or not, but Is there any better way to do so the laravel way?
Thanks,
K
you have 2 methods one is getDirty() by using this you will get current changed input value, another one is getOriginal() if you use that you will get what previous data you have
By using those 2 methods i am giving here a example,may be it will help you
static::saving(function($model)
{
foreach($model->getDirty() as $attribute => $value){
$original= $model->getOriginal($attribute);
echo "Changed $attribute from '$original' to '$value'<br/>\r\n";
}
return true; //if false the model wont save!
});

Merging a dynamic number of collections together

I'm working on my first laravel project: a family tree. I have 4 branches of the family, each with people/families/images/stories/etc. A given user on the website will have access to everything for 1, 2, or 4 of these branches of the family (I don't want to show a cousin stuff for people they're not related to).
So on various pages I want the collections from the controller to contain stuff based on the given user's permissions. Merge seems like the right way to do this.
I have scopes to get people from each branch of the family, and in the following example I also have a scope for people with a birthday this month. In order to show the right set of birthdays for this user, I can get this by merging each group individually if they have access.
Here's what my function would look like if I showed everyone in all 4 family branches:
public function get_birthday_people()
{
$user = \Auth::user();
$jones_birthdays = Person::birthdays()->jones()->get();
$smith_birthdays = Person::birthdays()->smith()->get();
$lee_birthdays = Person::birthdays()->lee()->get();
$brandt_birthdays = Person::birthdays()->brandt()->get();
$birthday_people = $jones_birthdays
->merge($smith_birthdays)
->merge($lee_birthdays )
->merge($brandt_birthdays );
return $birthday_people;
My challenge: I'd like to modify it so that I check the user's access and only add each group of people accordingly. I'm imagining something where it's all the same as above except I add conditionals like this:
if($user->jones_access) {
$jones_birthdays = Person::birthdays()->jones()->get();
}
else{
$jones_birthdays =NULL;
}
But that throws an error for users without access because I can't call merge on NULL (or an empty array, or the other versions of 'nothing' that I tried).
What's a good way to do something like this?
if($user->jones_access) {
$jones_birthdays = Person::birthdays()->jones()->get();
}
else{
$jones_birthdays = new Collection;
}
Better yet, do the merge in the condition, no else required.
$birthday_people = new Collection;
if($user->jones_access) {
$birthday_people->merge(Person::birthdays()->jones()->get());
}
You are going to want your Eloquent query to only return the relevant data for the user requesting it. It doesn't make sense to query Lee birthdays when a Jones person is accessing that page.
So what you will wind up doing is something like
$birthdays = App\Person::where('family', $user->family)->get();
This pulls in Persons where their family property is equal to the family of the current user.
This probably does not match the way you have your relationships right now, but hopefully it will get you on the right track to getting them sorted out.
If you really want to go ahead with a bunch of queries and checking for authorization, read up on the authorization features of Laravel. It will give let you assign abilities to users and check them easily.

Is it possible to set user parametr in joomla without session?

The default JUser::setParam() method sets parameters only to the session. Is is possible somehow to store parameters not in the session, that they would be always available? I also found in users table field params, which stores some parameters for current user, but don't know how to add data there...
Have you tried to save the object after adding your param?
$user = JFactory::getUser();
$user->setParam($key, $value);
$user->save;
An easy and comfortable approach would be to use the popular Community Builder Extension which lets you define custom user fields in the administrator backend. It has an API to obtain the CB User Object and to write and read those fields which get stored in the DB as opposed to the session. Simple example without knowing your Joomla/CB version (works with Joomla 2.5 and CB 1.8) and the place (site, admin, external) where this should be executed (assuming your parameter is named customParam and the user id is 42):
cbimport( 'cb.field' );
$mosCbUser = CBUser::getUserDataInstance(42);
// read value
$customParameter = $mosCbUser->customParam;
// write value
$mosCbUser->customParam = 'newnew';
$mosCbUser->store();
/* write value to DB directly with optional boolean third parameter
specifing whether to trigger the user update plugins
like onBeforeUserUpdate or onAfterUserUpdate
*/
$mosCbUser->storeDatabaseValue('cb_adresse', 'new address', false);
be sure to be in CB plugin context, if not already the case, include e.g. like
global $_CB_framework, $_CB_database, $ueConfig;
$app = JFactory::getApplication();
include_once( $app->getCfg( 'absolute_path' ) . '/administrator/components/com_comprofiler/plugin.foundation.php' );

Checking if specific user is online through php session variable

I'm currently trying to display all online users on my webpage using the php session variables. To do this, whenever a user logs in or out, a column in a database gets set to "online" or "offline".. However this doesn't entirely work since the database doesn't get updated when the user closes their browser (and therefor destroys the session).
So is there another way of checking if a certain sessionid is set??
Currently I am setting the session like this:
session_start();
$_SESSION['username']="Example Username";
To check from the current users page if there is a session variable set we can simply use:
if(isset($_SESSION['username']))
{
//username is set
}
But if we need to check if a specific user is online, how do we get for instance an array of all the session variables that have been set? e.g.
//Get all $_SESSION['username'] vars
//loop through array and check for specific $_SESSION
for($i=0; ... )
{
if( $_SESSION['username'][$i] == "User 1" )
{
//do something
}
}
From all that I've read so far, there doesn't seem to be a way to get an array of all sessions on your page..
So is there a better way of doing it, e.g. how do facebook, twitter, etc handle this stuff?
Thanks for your help!
One solution is to store a timestamp in your database in addition to the online/offline flag that records the last time a user accessed any of your website resources. Then you might just consider them offline after 15 minutes or some other constant value.
The other solution is to play with the callbacks here http://php.net/manual/en/function.session-set-save-handler.php where I think you can handle the gc callback and set the offline flag in your database.
If you search on that page for class SessionDB or go here it looks like somebody has implemented some version of this already in a custom class!
you can use a simple update query
for example you have a table users and in that you have a column called status(online/offline)
on your login.php use
<?php
//your user verification code
if(variable that holds your sql query){
$user_status=('UPDATE user SET status= online WHERE email="'your user email selector'")
}
then on the logout do a similar script just change the online value to offline
You could try this:
foreach ($_SESSION as $sessionKey => $sessionValue)
{
if( $sessionKey == 'username' ) && ( $sessionValue == 'User 1' )
{
//do something
}
}

Resources