I'm using Worklight Studio Plugin 6.0.
I am trying to get FormBasedAuthentication working. When I run and deploy my worklight project, the app login page is presented successfully. However when I click on the login button, an error is thrown on the server console:
[ERROR ] FWLSE0048E: Unhandled exception caught: SRVE0190E: File not found: /apps/services/j_security_check [project DojoTest]
SRVE0190E: File not found: /apps/services/j_security_check
This directory doesn't exist in the project. I've tried creating another project but it doesn't add the missing folder.
Any advise is appreciated. Thank you in advance.
<div id=BorderDiv>
<div class=imageDiv id="imageDiv">
<center style="color:#66FF66">
Test
</center>
</div>
<fieldset id="loginFieldSet">
<legend>Login:</legend>
<div data-dojo-type="dojox/mobile/FormLayout"
data-dojo-props="columns:'auto'">
<div>
<label>User name*: </label> <input id="username" type=text
data-dojo-type="dojox.mobile.TextBox" size="50"
placeholder="Enter Username" name="username" required></input>
</div>
<div>
<label>Password*: </label> <input id="password" type=password
name="pass" placeholder="Enter Password" size="50"
data-dojo-type="dojox.mobile.TextBox" required> </input>
</div>
</div>
<div>
<center>
<input type="button" class="formButton" id="AuthSubmitButton" value="Login" /> <input type="button" class="formButton" id="AuthCancelButton" value="Cancel" />
</center>
</div>
<!-- <button data-dojo-type="dojox.mobile.Button" onclick="login()">Login</button>-->
</fieldset>
</div>
//Create the challenge object
var challengeHandler = WL.Client.createChallengeHandler("SampleAppRealm");
/*
* Read the response of the challenge. The default login form
* that the server returns contains a j_security_check string.
* If the challenge handler detects it in the response, return true
*
*/
challengeHandler.isCustomResponse = function(response) {
if (!response || response.responseText === null) {
return false;
}
var indicatorIdx = response.responseText.search('j_security_check');
if (indicatorIdx >= 0) {
return true;
}
return false;
};
//Hanlde the Challenege. In our case, we do nothing!
challengeHandler.handleChallenge = function(response) {
//do nothing
};
//Bind the login button to collect the username and the password
$('#AuthSubmitButton').bind('click', function () {
var reqURL = 'j_security_check';
var options = {};
options.parameters = {
j_username : $('#username').val(),
j_password : $('#password').val()
};
options.headers = {};
challengeHandler.submitLoginForm(reqURL, options, challengeHandler.submitLoginFormCallback);
});
$('#AuthCancelButton').bind('click', function () {
alert("Cancel Clicked");
sampleAppRealmChallengeHandler.submitFailure();
});
challengeHandler.submitLoginFormCallback = function(response) {
var isLoginFormResponse = challengeHandler.isCustomResponse(response);
if (isLoginFormResponse){
challengeHandler.handleChallenge(response);
} else {
login();
$('#password').val('');
$('#username').val('');
challengeHandler.submitSuccess();
}
};
function login(){
require([ "dojo/dom", "dijit/registry" ], function(dom, registry) {
var username = dom.byId("username");
var password = dom.byId("password");
alert("username= " + username.value + " AND password = "
+ password.value);
try {
registry.byId("mainMenuView").performTransition("myAcctView", 1,
"slide");
WL.Logger.debug("Moved to My Account view");
} catch (e) {
WL.Logger.debug("Error Caught: " + e);
}
});
}
In form-based authentication it is expected from the server to send a login form in response to a connect attempt (you are not required to display the HTML sent by the server, it's just the response that matters mostly).
Basically, if your app's first screen is the login form and you click some login button and this button does a login attempt, it will first the first time, because only in the first time will the server get a request from the app and the response to that request would be the challenge - the login form.
So you need to make sure that you first connect to the server using WL.Client.connect and only then allow the user to do any login attempts (can be a login button). This is the usual scenario why the above error is given.
Note also that this is not a resource that exists in your Worklight project; it's a resource that exists on the server. This is why you cannot find it.
Please review the authentication concepts and form-based tutorial (and its sample) user documentation: http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.0.0/com.ibm.worklight.getstart.doc/start/c_gettingstarted.html?cp=SSNJXP
Related
In my Shopify theme, I'm creating a login form where when a user logs in, the customer object should be populated and it should know that the specific user is logged in so that I can use the customer object's properties anywhere in my project.
I want that following customer becomes true:
{%- if customer -%}
What I've done is used email to log inside account, first it check if email present then log inside, then it uses admin api to store the customer object inside another object. But I want that instead my customer object that is present in liquid should be updated that this user is logged inside.
<div id="login-container">
<form id="login-form">
<div>
<label for="email">Email:</label>
<input type="email" id="email" required>
</div>
<button type="submit" id="signInBtn">Login</button>
</form>
</div>
const email = localStorage.getItem("email");
const loginContainer = document.getElementById("login-container");
// form functionality
const form = document.getElementById("login-form");
form.addEventListener("submit", (e) => {
e.preventDefault();
var customerEmail = document.getElementById("email").value;
fetch('/admin/customers/search.json?email=' + customerEmail)
.then(function(response) {
return response.json();
})
.then(function(data) {
if (data.customers.length > 0) {
var customer = data.customers[0];
localStorage.setItem('customer', JSON.stringify(customer));
} else {
alert("User not found");
}
})
.catch(function(error) {
console.error('An error occurred:', error);
});
});
I have a SPA built in Vue.js - using JWT for authentication and an API layer provided by Laravel.
I now require a single page to run (outside the SPA/Vue) directly from Laravel, but only after the user has logged in. Once there i need to access Auth::user() - but it seems that Laravel doesn't now the user is actually logged in.
Not entirely sure what code to put here, but here goes anyway:
Login.vue
<template>
<div>
<div class="alert alert-danger" v-if="error">
<p class="help-block" v-if="errors">{{ errors }}</p>
<p class="help-block" v-else >There was an error, unable to sign in with those credentials.</p>
</div>
<form autocomplete="off" #submit.prevent="login" method="post">
<div class="form-group">
<label for="email">E-mail</label>
<input type="email" id="email" class="form-control" placeholder="user#example.com" v-model="email" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" class="form-control" v-model="password" required>
</div>
<button type="submit" class="btn btn-default">Sign in</button>
</form>
</div>
</template>
<script>
export default {
data(){
return {
email: null,
password: null,
error: false,
errors: {}
}
},
methods: {
login(){
var app = this
this.$auth.login({
params: {
email: app.email,
password: app.password
},
success: function (resp) {
//app.error = true;
//console.log('>>> '+resp.response.data.msg);
//app.errors = resp.response.data.msg;
},
error: function (resp) {
app.error = true;
//console.log('>>> '+resp.response.data.msg);
app.errors = resp.response.data.msg;
},
rememberMe: true,
redirect: '/dashboard',
fetchUser: true,
});
},
}
}
</script>
routes/api.php
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('auth/register', 'AuthController#register');
Route::post('auth/login', 'AuthController#login');
Route::post('findmember', 'FoundItemController#searchMember');
Route::post('sendmessage', 'MessagingController#sendMessage');
Route::group(['middleware' => 'jwt.auth'], function(){
//
// User auth controllers/methods should go here
//
Route::get('packages', 'PackageController#getPackages');
Route::get('auth/user', 'AuthController#user');
Route::post('auth/logout', 'AuthController#logout');
Route::get('user/items', 'ItemController#getItems');
Route::post('user/items/add', 'ItemController#addItem');
Route::get('user/mobile_numbers', 'MobileNumbersController#getNumbers');
Route::post('user/mobile_numbers/add', 'MobileNumbersController#addNumber');
Route::post('user/mobile_numbers/primary', 'MobileNumbersController#setPrimary');
Route::post('user/mobile_numbers/delete', 'MobileNumbersController#removeNumber');
Route::post('subscription/paypal/complete');
});
Route::group(['middleware' => 'jwt.refresh'], function(){
Route::get('auth/refresh', 'AuthController#refresh');
});
/routes/web.php
Route::get('/', function () {
return view('welcome');
});
Auth::routes(['verify' => true]);
Route::get('/verify', 'AuthController#verify')->name('verify');
Route::group(['middleware' => 'jwt.auth'], function(){
Route::get('testing', 'HomeController#index');
});
I tried adding the middleware wrapper around my home controller (see
below), but this returns null), I feel i need to tell Laravel
that the user is logged in somehow, but am completely stumped.
../controllers/HomeController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Illuminate\Support\Facades\Auth;
use JWTAuth;
use Log;
class HomeController extends Controller
{
public function index()
{
//return view('home');
dd(Auth::user());
}
}
I don't know laravel at all, but here is the general idea of what I would do, from your single page:
on a first request, query a route on laravel to get the jwt (sometime this route is /me).
on the next requests, inject the jwt in the page headers. The token name is token and the value is something like Bearer ${token}.
On the server side, check if the token is valid before to proceed the request.
Hope this helps.
you can use this method, I used in my project it work cool.
auth('api')->user();
I'm using the aurelia-dialog plugin to allow users to generate a set of objects, and want the dialog's response to return the chosen objects.
The workflow is that the list of options is generated from an API call using a promise when the activate() method is called on the dialog. The options are then displayed to the user, and selected from a dropdown. The user then clicks ok and the response should be sent back. Here is the code that is supposed to accomplish it:
this.ds.open({
viewModel: MyModal,
model: {
"title": "Select Objects",
"message": "I hate this modal"
}
}).then(response => {
console.log("closed modal");
console.log(response);
if (!response.wasCancelled) {
console.log('OK');
} else {
console.log('cancelled');
}
console.log(response.output);
});
And then in the modal.js:
import {inject} from 'aurelia-framework';
import {DialogController} from 'aurelia-dialog';
import {ModalAPI} from './../apis/modal-api';
//#inject(ModalAPI, DialogController)
export class MyModal {
static inject = [DialogController, ModalAPI];
constructor(controller, api){
this.controller = controller;
this.api = api;
controller.settings.centerHorizontalOnly = true;
}
activate(args){
this.title = args.title;
this.message = args.message;
this.returnedSet = null;
this.historicSetName = null;
this.reportHist = null;
return this.api.getReportHistory().then(reports => {
this.reportHist = reports;
});
}
selectHistoricReport() {
console.log(this.historicSetName);
if(this.historicSetName == "Select a report...") {
this.returnedSet = null;
} else {
var selectedReport = this.reportHist.filter(x => x.name == this.historicSetName)[0];
this.returnedSet = selectedReport.rsids;
}
console.log(this.returnedSet);
}
ok(returnedSet) {
console.log(returnedSet);
this.controller.ok(returnedSet);
}
}
And then the html:
<template>
<require from="../css/upload-set.css"></require>
<ai-dialog class="selector panel panel-primary">
<ai-dialog-header class="panel-heading">
<button type="button" class="close" click.trigger="controller.cancel()" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">${title}</h4>
</ai-dialog-header>
<ai-dialog-body class="panel-body container-fluid">
<div class="row">
<div class="col-sm-6">
<label>Report: </label>
<select value.bind="historicSetName" change.delegate="selectHistoricReport()" class="input-md form-control">
<option ref="historicSetPlaceholder">Select a report...</option>
<option repeat.for="historicReport of reportHist">${historicReport.name}</option>
</select>
</div>
</div>
</ai-dialog-body>
<ai-dialog-footer>
<button click.trigger="controller.cancel()">Cancel</button>
<button click.trigger="ok(returnedSet)">Save</button>
</ai-dialog-footer>
</ai-dialog>
</template>
As long as I don't touch the dropdown, the dialog will return a null (or any other value I initialize returnedSet to). However, as soon as I click on the dropdown, clicking either the Save or Cancel button leads to nothing being returned and the console.log lines at the end of my first code block just get skipped. I also tried removing the click.delegate line from my HTML, but that didn't change anything.
Anyone have any idea why this might be happening?
Also, I found this post(Aurelia Dialog and Handling Button Events) with an extremely similar problem, but can't seem to find any solution in there as to what I should do.
Thanks in advance.
I'm trying to use ids with my input box's within my login page but I get the following error with Protractor:
Failed: No element found using locator: By css selector, *[id="signin--username"])
Here is my log-in.js
var logIn = function() {
this.navigate = function() {
browser.get(browser.params.server);
};
this.usernameInputBox = element(by.id('signin--username'));
this.passwordInputBox = element(by.id('signin--password'));
this.dontHaveAnAccountButton = element(by.id('signin--no-account-question'));
this.logInButton = element(by.id('signin--log-in'));
this.Modal = element(by.css('.modal-dialog'));
this.ModalButton = element(by.xpath('//*[#id="app"]/div[3]/div/div/form/div[3]/button'));
};
module.exports = new logIn();
Snippet from log-in.html
<div class="form-group">
<div class="input-group input-group-lg">
<span class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
</span>
<input type="text"
id="signin--username"
class="form-control"
placeholder="{{'username' | translate}}"
ng-model="username"
name="username"
required
autofocus data-autofill
>
</div>
</div>
Protractor Test Javascript File:
module.exports = function() {
describe('Login Page', function() {
var loginPage = require('../pages/log-in.js');
var saveScreenshot = require('../screenshot.js');
beforeEach(function() {
loginPage.navigate();
})
it('should log in (with correct credentials)', function() {
browser.waitForAngular();
loginPage.usernameInputBox.sendKeys('service');
loginPage.passwordInputBox.sendKeys('s5rv1c5');
loginPage.logInButton.click();
browser.waitForAngular();
expect(browser.getCurrentUrl()).toContain(browser.params.server + '#/jobs/my_jobs');
})
});
};
Any help much appreciated! Thanks.
Looks like a timing issue. Improve navigate page object method to also wait for the page to load - wait for the username field to become present:
var logIn = function() {
this.usernameInputBox = element(by.id('signin--username'));
this.passwordInputBox = element(by.id('signin--password'));
this.dontHaveAnAccountButton = element(by.id('signin--no-account-question'));
// ...
this.navigate = function() {
browser.get(browser.params.server);
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(this.usernameInputBox), 5000, "Username field is still not present");
};
};
You are not giving the unique selector correctly. That is why this error occurs.
Use element(by.model('username')).sendKeys('your user name');
I assume that you gave the html of login text box.
Hope this helps. :)
first question on stackoverflow, so please tell me if my info is insufficient. Thanks in advance.
I'm trying to implement a firebase-simple-login, but the only error type I am getting is 'INVALID EMAIL' on the signIn function. If I enter an incorrect password with an existing email it still throws invalid e-mail.
$scope.signIn = function() {
$rootScope.auth.$login('password', {
email: $scope.email,
password: $scope.password
}).then(function(user) {
console.log("user has email " + user.email);
}, function(error) {
if (error = 'INVALID_EMAIL') {
console.log('email invalid or not signed up');
} else if (error = 'INVALID_PASSWORD') {
console.log('invalid password');
} else {
console.log(error);
}
});
};
For extra reference; the html with the corresponding form
<div class="form-group">
<input type="email" class="form-control" placeholder="email" ng-model="email" />
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="password" ng-model="password" />
</div>
<button type="submit" class="btn btn-success" ng-click="signIn()">Sign in</button>
I can't seem to find anything useful on error types in the firebase docs, so I hope you can help.
CreateUser is invoked as such:
$scope.signUp = function() {
$rootScope.auth.$createUser($scope.email, $scope.password, function(error,user) {
if (!error) {
console.log('User Id: ' + user.uid + ', Email: ' + user.email);
}
}).then(function(){
$rootScope.auth.$login('password', {
email: $scope.email,
password: $scope.password
});
});
};
This is the solution I found after inspecting the error function further. It seems you need to go into the error object, to error.code in stead of just error, as well as using the operator === instead of =. I had lifted the $login() straight from the firebase docs, but I might have mixed some things up in the process. Anyway, here's the working code.
function(error) {
if (error.code === 'INVALID_EMAIL') {
console.log('email invalid or not signed up');
} else if (error.code === 'INVALID_PASSWORD') {
console.log('invalid password');
}
You can actually use Firebase provided error messages instead of if clause.
function(error){
if(error){
console.log(error_code.message)
}
}