Create a custom login in wakanda 1.1.3 - wakanda

I am creating a Angular2 application in which i need a custom login instead of the existing directory login So, I added the following code and created some new files and code as the following
i added a new file login.js under the backend location with the following code
directory.setLoginListener("loginFuction","Admin");
I made changes to my require.js as the following
function loginFunction(email,password){
console.log("Call is being made to the backend");
var u = ds.User.find("email : 1" ,email);
console.log(u);
if(!u){
return false;
}else{
var token = currentSession.promoteWith("Admin");
if(u.password == password){
var theGroups = [];
switch(u.role){
case 'Admin':
theGroups.push('Admin');
break;
case 'Users':
theGroups.push('Users');
break;
}
var connectTime = new Date();
return {
ID : u.ID,
name : u.email,
fullName : u. fullname,
belongsTo : theGroups,
storage:{
time : connectTime
}
};
}else{
return {
error : 1024,
errorMessage : "invalid login"
}
}
}
};
when i call the loginFunction from my normal component like
this.wakanda.directory.login('adithya#gmail.com','adithya').then(res => {
console.log(res);
});
I am getting an error stating
EXCEPTION: Uncaught (in promise): Error: Directory.login: Unauthorized
All the table are being made global access, and everything is being made as public.
Can anyone help me with this solution.
Thanks in advance.

The exact method of creating the custom login in wakanda studio 1.1.3 is of the following we have to make change in the function call present in the bootstrap.js like the following
directory.setLoginListener("loginFunction");
by removing the "Admin" as the second parameter .

Related

Why Parse server is creating new object instead of updating?

I am running parse server in NodeJS environment with express.
Generally, Parse automatically figures out which data has changed so only “dirty” fields will be sent to the Parse Cloud. So, I don’t need to worry about squashing data that I didn’t intend to update.
But why this following code is saving new data every time instead of updating the existing document data with name "Some Name".
// Parse code
Parse.initialize(keys.parseAppID);
Parse.serverURL = keys.parseServerURL;
var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();
let data = {
playerName: "Some Name",
score: 2918,
cheatMode: true
};
gameScore.save(data, {
success: (gameScore) => {
// let q = new Parse.Query("GameScore");
// q.get(gameScore.id)
console.log("ID: " + gameScore.id)
},
error: function (gameScore, error) {
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Failed to create new object, with error code: ' + error.message);
}
});
// End of Parse code
The problem is that you're executing the query to find which object you want to update, but then you're not using the results when you go to save data.
query.first({ // This will result in just one object returned
success: (result) => {
// Check to make sure a result exists
if (result) {
result.save(data, {
// Rest of code
Note: You're treating playerName as a unique key. If multiple users can have the same playerName attribute, then there will be bugs. You can use id instead which is guaranteed to be unique. If you use id instead, you can utilize Parse.Query.get
Edit:
Since you want to update an existing object, you must specify its id.
var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();
gameScore.id = "ID"; // This id should be the id of the object you want to update

Can update a users password in localhost but not on shared hosting server

This is the function to update user password
function update_systemusers_password($input) {
$systemusers = users::find($input['userid']);
$systemusers->password = bcrypt($input['password']);
$systemusers->save();
}
however it doesn't update in shared hosting server
First of all you need to confirm that your function is execute or not. Try something like this to make sure.
function update_systemusers_password($input) {
dd($input); // it will show the all of input
$systemusers = users::find($input['userid']);
$systemusers->password = bcrypt($input['password']);
$systemusers->save();
}
if dd(); print all the value of request then remove the dd(); inside the function and write some condition for confirmation.
function update_systemusers_password($input) {
$systemusers = users::find($input['userid']);
$systemusers->password = bcrypt($input['password']);
if($systemusers->save()){
dd("save successfully");
}
else{
dd("found error");
}
}

Modifying Parse.User object before FIRST save

I'm working on an app and I need some changes to be made on new users registering during certain periods.
I've added a variable which I will change manually, and a check if that value is true or false.
This is my current code:
Parse.Cloud.beforeSave(Parse.User, function(request, status)
{
console.log("********************************************");
Parse.Cloud.useMasterKey();
var special = true;
if(special)
{
request.object.set("points", 1000);
request.object.set("role/objectid", "PZHTquGti0");
}else{
request.object.set("points", 0);
request.object.set("role/objectid", "TQyjIY59oL");
}
console.log("********************************************");
status.success("Job finished successfully!");
}); // end of Parse.define
This code errors out with "Uncaught Error: change must be passed a Parse.Object" and I've been looking through the documentation to find out how to change a value of a subclass of the User object, but have found none.
Also, this code will also run when updating a user, which I don't want it to do.
Any help is highly appreciated!
First of all for running the code on first save (insert), you can use request.object.isNew()
As the role column is a pointer, you should set an object & not the id string directly.
So create a new dummy object and assign the id to it.
Parse.Cloud.beforeSave(Parse.User, function(request, status)
{
console.log("********************************************");
Parse.Cloud.useMasterKey();
if(request.object.isNew()){ // Object Insert
var Role = Parse.Object.extend("_Role");
var role = new Role();
var special = true;
if(special)
{
request.object.set("points", 1000);
role.id = "PZHTquGti0";
request.object.set("role", role);
}else{
request.object.set("points", 0);
role.id = "TQyjIY59oL";
request.object.set("role", role);
}
}
else{ // Object Update
//Do nothing
}
console.log("********************************************");
status.success("Job finished successfully!");
}); // end of Parse.define

Error in processing entity WorkOrder unable to create entity object

I am receiving the following error calling GetAssetEquipmentOp:
"Error in processing entity WorkOrder unable to create entity object"
Here is the code so far:
public stringType getAssetDescription(string equipmentcode)
{
try
{
// Setup Service Objects
MP0302_GetAssetEquipment_001.GetAssetEquipmentService getservice = new MP0302_GetAssetEquipment_001.GetAssetEquipmentService();
MP0302_GetAssetEquipment_001.MP0302_GetAssetEquipment_001 getrequest = new MP0302_GetAssetEquipment_001.MP0302_GetAssetEquipment_001();
MP0302_GetAssetEquipment_001.MP0302_GetAssetEquipment_001_Result getresult = new MP0302_GetAssetEquipment_001.MP0302_GetAssetEquipment_001_Result();
// Setup Return Object
stringType desc = new stringType();
// Setup Service Parameters
getrequest.ASSETID = new MP0302_GetAssetEquipment_001.EQUIPMENTID_Type();
getrequest.ASSETID.EQUIPMENTCODE = equipmentcode;
getrequest.ASSETID.ORGANIZATIONID = new MP0302_GetAssetEquipment_001.ORGANIZATIONID_Type();
getrequest.ASSETID.ORGANIZATIONID.ORGANIZATIONCODE = _orgCodeBody;
// Setup Datastream Object
Datastream.EWS.Session sess = new Datastream.EWS.Session(_userid, _passwd, _orgCodeHead, _url, _tenant, false);
// Prepare Service Request
sess.PrepareServiceRequest(getservice);
// Call Web Service and get result
getresult = getservice.GetAssetEquipmentOp(getrequest);
// Extract Description
desc.stringValue = getresult.ResultData.AssetEquipment.ASSETID.DESCRIPTION;
desc.errorNum = 0;
// Close Up/Dispose
sess.CompleteServiceRequest(getservice);
sess.Dispose();
// Return value
return desc;
}
catch (Exception ex)
{
stringType errorStringType = new stringType();
errorStringType.errorNum = 1;
errorStringType.errorDesc = ex.Message;
return errorStringType;
}
}
I have checked the following:
- User group has interface permissions including BECONN
- User has "Connector" option selected
- User has status authorizations including * to Q for EVNT
Any help would be appreciated.
Problem solved! The problem was that the work order number did not exist. It is a very misleading error but once an existing work order was tested, it fetched the work order with no issues.

EntitySqlException when trying to access DbUpdateConcurrencyException's GetDatabaseValues() entity

I'm trying to do the tutorial here: http://www.asp.net/entity-framework/tutorials/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application
In the ActionResult Edit, I have the following code:
public ActionResult Edit(Product product)
{
try
{
if (ModelState.IsValid)
{
db.Entry(product).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
}
catch(DbUpdateConcurrencyException ex)
{
var entry = ex.Entries.Single();
var databaseValuesObj = entry.GetDatabaseValues().ToObject();
var databaseValues = (Product)databaseValuesObj;
var clientValues = (Product)entry.Entity;
if (databaseValues.Name != clientValues.Name)
ModelState.AddModelError("Name", "Current value: "
+ databaseValues.Name);
if (databaseValues.Description != clientValues.Description)
ModelState.AddModelError("Description", "Current value: "
+ String.Format("{0:c}", databaseValues.Description));
if (databaseValues.ControllingStudentId != clientValues.ControllingStudentId)
ModelState.AddModelError("ControllingStudentId", "Current value: "
+ String.Format("{0:d}", databaseValues.ControllingStudentId));
ModelState.AddModelError(string.Empty, "The record you attempted to edit "
+ "was modified by another user after you got the original value. The "
+ "edit operation was canceled and the current values in the database "
+ "have been displayed. If you still want to edit this record, click "
+ "the Save button again. Otherwise click the Back to List hyperlink.");
product.Timestamp = databaseValues.Timestamp;
}
catch (DataException)
{
//Log the error (add a variable name after Exception)
ModelState.AddModelError(string.Empty, "Unable to save changes. Try again, and if the problem persists contact your system administrator.");
}
return View(product);
}
On the var databaseValuesObj = entry.GetDatabaseValues().ToObject(); line, I get an exception like this:
System.Data.EntitySqlException was unhandled by user code
Message=Type 'MvcApplication3.DAL.Product' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly. Near type name, line 1, column 119.
Source=System.Data.Entity
Column=119
ErrorContext=type name, line 1, column 119
ErrorDescription=Type 'MvcApplication3.DAL.Product' could not be found. Make sure that the required schemas are loaded and that the namespaces are imported correctly.
Line=1
...
My question is, how can I show it where the Product class is? Its in the project and I've got the using statement at the top. Why can't it find it?
Edit:
Based on the response below, I changed my code to:
var entry = ex.Entries.Single();
var currentValues = entry.CurrentValues.Clone();
entry.Reload();
entry.CurrentValues.SetValues(currentValues);
var clientValues = (Product)entry.Entity;
var databaseValues = (Product)entry.OriginalValues.ToObject();
And that seemed to fix it. But I think it will have issues if the row is deleted. My current problem won't have that issue, so this is a good fix for me. Thanks!
This is a known issue when the context is in a different projects. No workarounds currently exist except for moving the context into the same project.
http://social.msdn.microsoft.com/Forums/en-HK/adodotnetentityframework/thread/fa67aa0e-3bca-44a5-9e00-af6362a539a7
EDIT
Actually I take that back - there is a workaround now listed there since the last time I read this. cool : )

Resources