Jdbc statement error - spring

I have problem with such simple thing, sql statement, I have table in database that contains link in varchar(255), people are logged to site by links, so I'm taking logged person name (Getting something like http://something.site.com) and then passing it to method in which I'm query database to get all records where my logged user has entries.
jdbcTemplate.query("Select * from HIRE where USER=(?)",new Object[] { userName },
However it gives no results at all. I have checked the value in HIRE and the userName are exactly the same, what have I missed?

Related

How to get user names and pictures of people leaving comments on a Facebook page you manage?

The field "from" returns nothing in this query:
https://graph.facebook.com/v3.2/(page id)?fields=posts{comments{message,created_time,from}}&access_token=(page access token)
The other fields return what I expect.
I'm administrator of the page but I haven't submitted my app for review because according to this page I don't have too, or am I wrong?
From the page:
Does not require App Review.
Grants your app access to the default fields of the User object that
are a subset of a person's public profile:
id
first_name
last_name
middle_name
name
name_format
picture
short_name
Or is there anything else I could have done wrong?
Without authorization, you cannot get any user specific data anymore, no matter if you own the Page in question. You can only get data like the message or the link to facebook.com.

Service Now GlideRecord query reference fields

Does Service Now allow querying referenced fields through the GlideRecord? And if so, how?
I have an application with a local user table for preferences specific to the application. When a user fills out a new form, I would like to query the local user table to see if a record exists for the currently logged in user. If it does, then I would like to prefill some of the answers on the form.
My user table has a reference to the sys_user table in order to link the local user record to the actual service now user. When I try to run the script to check the local user table, it returns "sys_idNotValidnull" for the query statement I add.
var lscUser = new GlideRecord('x_wadm_lsc_user');
lscUser.addQuery('UserID', '=', gs.getUserID());
gs.info("Query: "+lscUser.getEncodedQuery());
lscUser.query();
Returns: "Query: sys_idNotValidnull"
If I change the query to search a different string field it works as expected.
var lscUser = new GlideRecord('x_wadm_lsc_user');
lscUser.addQuery('temp', '=', 'dan');
current.temp += " Query: "+lscUser.getEncodedQuery();
Returns: "Query: temp=dan"
I would agree with Dan that the first step should be to confirm the column names. I usually don't take anything for granted, and always double check. You can use the dictionary or right click on the field label and it will show the column name.
I have seen "sys_idNotValidnull", but usually only within scoped applications.

MVC3 User Authentication link

In my application I have an administrator who can create Tournament objects. When the object is created the service also creates a user (based on the tournament director's info which was entered at creation). The username for the user is the director's e-mail, the password is randomly generated and then mailed to the director.
When the director logs on with his e-mail address and password, I need to be able to link him to his own tournament, in order to only allow him to edit his own tournament's details. I have tried to find a way to store the TournamentId in the default ASP Net Users database, but was unsuccessful.
I had a look at this SO question which would certainly help me, but I can't figure out how it would apply to my problem. When the user logs on, I can't put the TournamentId in the userdata seeing as I don't know it.
Should I then do a lookup in the Tournament table to see which ID corresponds to the email address entered at login and store that in the userData? It seems quite unelegant this way.
I guess you should have a CreatedBy column in your Tournament table where you store the ID of the user who created the tournament. Then when the user logged in, get his id ( may be from session ,if you store it there), Do a select query where CreatedBy=loggedInUserId .That should do the trick.

What reasons could cause WebSecurity.ChangePassword() to FAil?

I'm working on a Razor project and need to integrate an existing User database into the SimpleMembership Provider DB Schema. This is done by specifying my existing User table and which columns are to be used by the SimpleMembership API for the Username and UserID.
WebSecurity.InitializeDatabaseConnection("DB_ConnStr", "User", "UserId", "Username", true);
In the process though, I am populating the webpages_Membership table with a new record for each User row in my existing database. This has gone fine and I have written some code to handle the inserts for each existing user.
During the insert, I use a dummy encrypted password token for simplicity and set the password to be the same for everyone. Then I need to run another script over the records to set the correct password for each user in the webpages_Membership table. This involves decrypting the current password from the existing User table, and then calling:
WebSecurity.ChangePassword( username, dummyPwd, newPwd)
on each user, passing the decrypted current password as the 'newPwd' parameter.
This works fine in 99% of the cases that it's called - for over 100,000 records. But it is failing in about 40 cases.
What reasons could cause this method to fail?
My first guess would be that the hash of the new password might be exceeding the 128 character limit.
When the ChangePassword call fails, can you catch the exception to get details behind the reason of the failure?

How to connect a users table correctly to a Membership table, or should you even do that?

I'm probably going about this the wrong way, please feel free to correct me.
Currently I have a User model called U_USER, it contains fields such as address, receiveNotifications, HasCompanyCar Etc.
These users have roles in a .NET Membership table. When the user logs in via Membership, I get their user record in my database as follows (the username on the Membership table and my own U_USER table will have a match):
//Gets the current user
public U_USER CurrentUser()
{
return GetUser(HttpContext.Current.User.Identity.Name);
}
//Gets user details by username
public U_USER GetUser(String username)
{
return (from u in db.U_USER
where u.UserName == username
select u).FirstOrDefault();
}
If I wanted to get a list of all users in, lets say, the "Create" role then I would do this:
allUsers.Where(x => Roles.IsUserInRole(x.UserName, "Create"))
This is a big performance hit as it's doing a lookup for each iteration of a user. This makes me think I'm not going about user management in the correct way. So to answer this question:
How should you properly connect Membership to a users table that in turn is connected to the rest of your data? I'd also accept how to just go about it more efficiently!
Many thanks :)
EDIT :
I've increased performance via the below code. I get the users in the role in one swoop and then filter them.
String[] usersInRole = Roles.GetUsersInRole("CanApprove");
users = users.Where(x => usersInRole.Any(y => y == x.UserName));
But I'm still fairly sure I'm going about this ALL wrong!
Not an expert in this, but what my apps typically do is to use a foreign key (with Index) from my own Users table to the Membership Users table using the Guid field with the Membership. This then allows me to do queries using Linq like:
var query = from myUser in MyUsers
join aspUser in aspnet_Users on myUser.UserId equals aspUser.UserId
join usersInRole in aspnet_UsersInRoles on aspUser.UserId equals usersInRole.UserId
join role in aspnet_Roles on usersInRole.RoleId equals role.RoleId
where role ...
select new { ... };
(Or you can use dot-form like myUser.AspUser.Roles.Role to let the ORM generate the joins if you prefer)
For performance, it's good to watch the SQL trace occasionally - make sure you're not making too many SQL round-trips for each logical step in code.
Hope that helps a bit.
Update - in answer to your questions about "should you even do that", I think "yes" but there are other options available - e.g. you can use Profile fields - see Step 6 in this great walkthrough - https://web.archive.org/web/20211020202857/http://www.4guysfromrolla.com/articles/120705-1.aspx
We have created EntityFramework entities for all of the AspNet membership tables, this lets us query them like any other entity.
Not sure if it is what your after but may help

Resources