laravel 5.5 built in authenticate feature database query location - database

i am using laravel in windows OS, with MySql as the database, and am trying to connect my web application's login to laravel default login/registration. the default query that runs in laravel on login is select * from users where email="something" i want to know where this query is located in order to modify it according to my preferred table format. any help would be appreciated. thanks

This is located in the AuthenticatesUsers trait via the attemptLogin method:
/**
* Attempt to log the user into the application.
*
* #param \Illuminate\Http\Request $request
* #return bool
*/
protected function attemptLogin(Request $request)
{
return $this->guard()->attempt(
$this->credentials($request), $request->filled('remember')
);
}
The actual implementation is done with guards via the attempt method:
public function attempt(array $credentials = [], $remember = false)
See the Illuminate\Auth\SessionGuard for an example:
https://github.com/laravel/framework/blob/5.5/src/Illuminate/Auth/SessionGuard.php#L347

Related

user: getMemberGroups method is not present in Graph java sdk 1.6

I am using graph API JAVA sdk(v1.6.0) and I am trying to get all the groups that a specific user is in.
https://learn.microsoft.com/en-us/graph/api/user-getmembergroups?view=graph-rest-1.0&tabs=java#example
According to API doc, I could do something like below:
graphClient.me()
.getMemberGroups(securityEnabledOnly)
.buildRequest()
.post();
However, in java sdk 1.6.0, getMemberGroups() is not present under UserRequestBuilder.java class.
https://github.com/microsoftgraph/msgraph-sdk-java/blob/0041e58287f02036c37a8ae0a1bf30f1f616991a/src/main/java/com/microsoft/graph/requests/extensions/UserRequestBuilder.java.
Am i missing something?
I think they have replaced the getMemberOf() method with another one memberOf().
I was able to fetch all the groups for a particular user using the below code:
public static void getUserGroups(String accessToken) {
ensureGraphClient(accessToken);
String upn="test#testDomain.com";
IDirectoryObjectCollectionWithReferencesPage iDirectoryObjectCollectionWithReferencesPage = graphClient.users(upn).memberOf().buildRequest().get();
List<DirectoryObject> directoryObjects = iDirectoryObjectCollectionWithReferencesPage.getCurrentPage();
for (DirectoryObject directoryObject : directoryObjects) {
if(directoryObject.oDataType.equalsIgnoreCase("#microsoft.graph.group")) {
System.out.println(directoryObject.getRawObject().get("displayName"));
}
}
}

Laravel - How to globally show soft deleted users based on a condition?

I have a social network type site where there is the normal front end and an admin interface for me to log into.
I want to be able to exclude all soft deleted records (as it does anyway) from the front end, but in the admin I want them to be included in every query, so I can view them in a list, edit them, etc..
I've tried using a global scope with the withTrashed method, and also tried removing the SoftDeletingScope scope, but neither of them seem to work, it still excludes these models when using the query builder. e.g.
/**
* The "booting" method of the user model.
*
* #return void
*/
protected static function boot()
{
parent::boot();
if ( Auth::user()->isAdmin() ) {
static::addGlobalScope('showDeleted', function(Builder $builder) {
$builder->withTrashed();
});
// or
static::addGlobalScope('showDeleted', function(Builder $builder) {
$builder->removeGlobalScope(SoftDeletingScope::class);
});
}
}

Retrieve salesforce instance URL instead of visualforce instance

From a visualforce page, I need to retrieve our organization's salesforce instance's URL, and not the visual force URL.
For example I need https://cs1.salesforce.com instead of https://c.cs1.visual.force.com
Here's what I've tried so far and the outcome I got:
Accessed the Site global variable from the VF Page:
<apex:outputText value="{!$Site.Domain}" /> returns null
Sidenote: Everything in $Site.xxx seems to return null.
From the Apex controller:
public String getSfInstance()
{
return ApexPages.currentPage().getHeaders().get('Host');
}
and
public String getSfInstance()
{
return URL.getSalesforceBaseUrl().toExternalForm();
}
returns c.cs1.visual.force.com and https://c.cs1.visual.force.com, respectively.
Question: How do I retrieve what I want: https://cs1.salesforce.com?
Here's something that I used within my Apex Trigger
System.URL.getSalesforceBaseUrl().getHost().remove('-api' );
This gives me proper URL
This is a known issue, the URL.getSalesforceBaseUrl() should provide this information but it does not. However in reality this has very limited functional impact.
Their instance and apex domains are interchangeable in the sense that requesting a URL that does not belong to one gets redirected to the other.
for example if you seek /apex/myPage from cs1.salesforce.com you'll get redirected to c.cs1... and vise versa requesting /ID from apex domain will get you redirected to instance domain (unless detail action has been overridden)
If this does not help you there is one workaround, albeit very ugly :) create a custom object to store the base url and create before insert/update trigger which will set the baseURL field to URL.getSalesforceBaseUrl().toExternalForm(). Apparently trigger is the only place on the platform where this will work (aside from execute anonymous which is not of much use). When setting up the app insert something into that table and later use SOQL to retrieve base url.
Here is an Apex property that you can throw into a Utility class that will reliably return the instance for your org. Using this, you can easily construct your organization's Salesforce URL by appending ".salesforce.com" to the Instance:
public class Utils {
// Returns the Salesforce Instance that is currently being run on,
// e.g. na12, cs5, etc.
public static String Instance {
public get {
if (Instance == null) {
//
// Possible Scenarios:
//
// (1) ion--test1--nexus.cs0.visual.force.com --- 5 parts, Instance is 2nd part
// (2) na12.salesforce.com --- 3 parts, Instance is 1st part
// (3) ion.my.salesforce.com --- 4 parts, Instance is not determinable
// Split up the hostname using the period as a delimiter
List<String> parts = System.URL.getSalesforceBaseUrl().getHost().replace('-api','').split('\\.');
if (parts.size() == 3) Instance = parts[0];
else if (parts.size() == 5) Instance = parts[1];
else Instance = null;
} return Instance;
} private set;
}
// And you can then get the Salesforce base URL like this:
public static String GetBaseUrlForInstance() {
return 'https://' + Instance + '.salesforce.com';
}
FYI: For Scenario (1), the 1st of the 4-part hostname can get really complicated, but you'll always be able to find the Instance name as the 2nd part. For those who are interested, the syntax of Scenario 1 follows this pattern:
<MyDomain>--<SandboxName>--<Namespace>.<Instance>.visual.force.com
Here you have a quite nice and small snippet, that does, what it should for VisualforcePages :-)
String sUrlRewrite = System.URL.getSalesforceBaseUrl().getHost();
// Example: c.cs7.visual.force.com
sUrlRewrite = 'https://'
+ sUrlRewrite.substring(2,6)
+ 'salesforce.com'
+ '/'
+ recordId;
// Returns: https://cs7.salesforce.com/00kM00000050jFMIAY
Use:    Url.getOrgDomainUrl().toExternalForm()
Thanks, Tim Lewis
Note behaviour changes between releases and is sensitive to My Domain settings:
#Future context returns https://na1.salesforce.com
Visualforce context returns https://na1.salesforce.com
Force.com Site context returns https://na1.salesforce.com
#Future context returns https://mydomain.my.salesforce.com
Visualforce context returns https://mydomain.my.salesforce.com
Force.com Site context returns https://mydomain.my.salesforce.com
My Domain is mandatory in new orgs effective Winter '21.
Enhanced Domains is mandatory in all orgs effective Summer '22.
// Not to be confused with Url.getSalesforceBaseUrl()
// http://na1.salesforce.com (can happen in async apex)
// https://c.na1.visual.force.com (local Visualforce Page)
// https://ns.na1.visual.force.com (packaged Visualforce Page)
// https://custom.my.salesforce.com (org has My Domain enabled)
// https://sandbox-mydomain.na1.force.com (sandbox site with My Domain...)
See also the Salesforce Identity API which attests the pod/instance endpoint.
Fix to Alex_E snippet:
String sUrlRewrite = System.URL.getSalesforceBaseUrl().getHost();
String sfBaseProtocol = System.URL.getSalesforceBaseUrl().getProtocol();
//remove namespace
integer firstDotPos = sUrlRewrite.indexOf('.');
sURlRewrite = sURlRewrite.substring(firstDotPos+1);
//replace visual.force with salesforce
sURlRewrite = sURlRewrite.replace('visual.force', 'salesforce');
sUrlRewrite = sfBaseProtocol+'://'+sURlRewrite;
serverURL = sUrlRewrite;
This works for me:
String sUrlRewrite = System.URL.getSalesforceBaseUrl().getProtocol()
+ '://' + System.URL.getSalesforceBaseUrl().getHost()
+ '/' + record.Id;
Here is something to do with regex
public String getURL() {
return String.format(
'https://{0}.salesforce.com',
new String[]{
URL.getSalesforceBaseUrl().getHost().substringAfter('.').substringBefore('.')
});
}

Extending the CakeRequest Object

I have a web application written in CakePHP that needs to read request data from a JSON payload as opposed to standard application/x-www-form-urlencoded data. I would like to be able to access this data via the standard $this->request->data methodology. Is there a supported way to extend the CakeRequest object so that it is able to accept requests in this format?
Here's how you can customize the CakeRequest object's functionality:
Insert the following into app/Config/bootstrap.php:
/**
* Enable customization of the request object. Ideas include:
* * Accepting data in formats other than x-www-form-urlencoded.
*/
require APP . 'Lib' . DS . 'Network' . DS . 'AppCakeRequest.php';
Create app/Lib/Network, and add AppCakeRequest.php:
<?php
/**
* AppCakeRequest
*
* Allows for custom handling of requests made to the application.
*/
class AppCakeRequest extends CakeRequest {
// Do your magic, and be careful...
}
Edit app/webroot/index.php:
$Dispatcher->dispatch(new AppCakeRequest(), new CakeResponse(array('charset' => Configure::read('App.encoding'))));
Be careful, make sure you know what you're doing, and good luck.

get model data from a folder outside of the cakePHP app folder

I have a site where the directories are set up like this
public_html/framework/cake
public_html/framework/app
public_html/index.php
public_html/contact.php
public_html/aboutus.php
Is there any way to get variables or model data from public_html/framework/app when a user navigates to public_html/aboutus.php?
I would recommend reading the HttpSocket documentation.
An example implementation would look similar to:
/**
* import HttpSocket class
*/
App::import('Core', 'HttpSocket');
/**
* instantiate and make a POST request to http://localhost/contact.php
* sending var1 => test
*/
$HttpSocket = new HttpSocket();
$HttpSocket->post('http://localhost/contact.php', array(
array('var1' => 'test')
));
/**
* response
*/
$response = $HttpSocket->response;

Resources