QuickBlox: How to change password of user after login? - quickblox

Is there any way to change password of the user after login ?
Thanks

Sure
QBUUser *user = [QBUUser user];
user.ID = 300;
user.oldPassword = #"fgrhpass";
user.password = #"newpassword";
[QBUsers updateUser:user delegate:self];

Related

SFAuthorizationPluginView example NameAndPassword hangs after button is pressed

I'm using the patched version of NameAndPassword as is here: https://github.com/skycocker/NameAndPassword
When using this outside of the login window (e.g. system.login.screensaver or my own test right), with only the NameAndPassword plug-in, the window hangs for about 10 seconds after pressing Ok or cancel.
Adding some logs, I see that MechanismDestroy is getting called on the plugin and NameAndPassword is released but it never gets to dealloc in NameAndPassword. I also don't see PluginDestroy getting called. The SecurityAgent hangs around for an additional 10 seconds after MechanismDestroy is called.
I saw this related post: SecurityAgentPlugin not working anymore on Yosemite (SFAuthorizationPluginView)
But following the accepted answer doesn't work and according to the Authorization Plug-in Reference didDeactivate shouldn't need to be called (there are no calls to RequestInterrupt and MechanismDeactivate is never called). Calling SetResult should be sufficient.
I can hack it by getting the window from the view and closing it forcibly but there must be a way to get it to work as intended.
I found different hack - I got the reference count of the auth-mechanism instance and release all but the last one. Do this after the setResult call.
This solves the issue. It shouldn't be like that - but Apple doesn't give us much of a choice.
If my reply cant help someone, i have had the same problem and find a different way (not clean, it's even rather dirty) because i could not make the proposed solutions work.
I destroy the window if the identifiers are valid (I test them). Like that if the identifiers are not valid the window is still there.
- (void)buttonPressed:(SFButtonType)inButtonType
{
NSString *userNameString;
NSString *passwordString;
userNameString = mUserName;
passwordString = [mPPasswordSecureTextField stringValue];
// if the OK button was pressed, write the identity and credentials and allow authorization,
// otherwise, if the cancel button was pressed, cancel the authorization
if (inButtonType == SFButtonTypeOK)
{
const char *puserName = [userNameString UTF8String];
const char *ppassword = [passwordString UTF8String];
AuthorizationValue userNameValue = { strlen(puserName) + 1, (char*)puserName };
AuthorizationValue userPasswordValue = { strlen(ppassword) + 1, (char*)ppassword };
// add the username and password to the context values
[self callbacks]->SetContextValue([self engineRef], kAuthorizationEnvironmentUsername, 1, &userNameValue);
[self callbacks]->SetContextValue([self engineRef], kAuthorizationEnvironmentPassword, 1, &userPasswordValue);
// allow authorization
[self callbacks]->SetResult([self engineRef], kAuthorizationResultAllow);
// to know if we must close the window
// try to auth with the provided user and pswd
BOOL status = [self macosTestLogin: puserName with: ppassword];
if(status == YES)
{
// the user and pwd are good, we can close the window
NSView* v;
// if we are in sleep, screensaver and lock mode (don't work in loggin mode,
// but don't be sad loggin mode have a workaround in config authdb,
// the setting is shared true)
if (mUseIPView) {
v = mPasswordView;
NSWindow* w = [v window];
[w close];
}
}
// suggested workaround (don't work)
[self didDeactivate];
}
else if (inButtonType == SFButtonTypeCancel)
{
// cancel authorization
[self callbacks]->SetResult([self engineRef], kAuthorizationResultUserCanceled);
}
}
And the test function :
- (BOOL) macosTestLogin: (const char *)userName with: (const char *)password
{
// hack to know if we must close the window
// try to auth with the provided user and pswd
AuthorizationRef authorization = NULL;
AuthorizationItem items[2];
items[0].name = kAuthorizationEnvironmentPassword;
items[0].value = (char*) password;
items[0].valueLength = strlen(password);
items[0].flags = 0;
items[1].name = kAuthorizationEnvironmentUsername;
items[1].value = (char*) userName;
items[1].valueLength = strlen(userName);
items[1].flags = 0;
AuthorizationRights rights = {2, items};
AuthorizationEnvironment enviroment = {2, items};
// creates a new authorization reference and provides an option to authorize or preauthorize rights.
AuthorizationCreate(NULL, &enviroment, kAuthorizationFlagDefaults, &authorization);
AuthorizationFlags flag = kAuthorizationFlagDefaults| kAuthorizationFlagExtendRights;
OSStatus status = AuthorizationCopyRights(authorization, &rights, &enviroment, flag, NULL);
if(status == errAuthorizationSuccess)
{
return YES;
}
return NO;
}
This work for me, i do this only in 'screensaver' mode, on login the option shared = true is sufficient.

Error message from Cloud-Code, using parse.com

I'm developing a new App where I request users to sign up via the phone number, so that I can store it in Parse.com's database. I am doing it to use the same phone numbers to send push notifications.
I have been trying to accomplish this by using Twilio and Parse.com. I read the tutorial here and I tried to follow it without success.
Link to the tutorial here.
This is my cloud code (as seen in the URL linked above )
var twilio = require('twilio')('removed', 'removed');
Parse.Cloud.define("sendVerificationCode", function(request, response) {
var verificationCode = Math.floor(Math.random()*999999);
var user = Parse.User.current();
user.set("phoneVerificationCode", verificationCode);
user.save();
twilio.sendSms({
From: "+46 10 138 91 84",
To: request.params.phoneNumber,
Body: "Your verification code is " + verificationCode + "."
}, function(err, responseData) {
if (err) {
response.error(err);
} else {
response.success("Success");
}
});
});
Parse.Cloud.define("verifyPhoneNumber", function(request, response) {
var user = Parse.User.current();
var verificationCode = user.get("phoneVerificationCode");
if (verificationCode == request.params.phoneVerificationCode) {
user.set("phoneNumber", request.params.phoneNumber);
user.save();
response.success("Success");
} else {
response.error("Invalid verification code.");
}
});
And this is the code I call in Xcode:
NSString *number = #"0737879108";
NSDictionary *params = [NSDictionary dictionaryWithObject:number forKey:#"number"];
//NSLog(#"%#", params);
[PFCloud callFunctionInBackground:#"sendVerificationCode" withParameters:params block:^(id object, NSError *error) {
NSString *message = #"";
if (!error)
message = #"Your SMS invitation has been sent!";
} else {
message = #"Uh oh, something went wrong :(";
}
[[[UIAlertView alloc] initWithTitle:#"Invite Sent!"
message:message
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil, nil] show];
}];
Why am I getting this error message?
TypeError: Cannot call method 'set' of null
at main.js:7:10 (Code: 141, Version: 1.6.1)
The error is pretty straightforward. You use user to call the set method. And it says that TypeError: Cannot call method 'set' of null. So, the problem is about you called user. Try to debug the user or check whether Parse.User.current() return proper user.

How to retrieve XMPP user information

I need to retrieve user information saved on openfire server.
XMPPvCardCoreDataStorage* xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
XMPPvCardTempModule* m = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
[m fetchvCardTempForJID:[sender myJID]];
How/where I can read result of request? Is the right way to "query" openfire server?
I also tryed:
XMPPIQ *iq = [[XMPPIQ alloc] initWithType:#"get"];
[iq addAttributeWithName:#"id" stringValue:#"v1"];
[iq addAttributeWithName:#"from" stringValue:[NSString stringWithFormat:#"%#", sender]];
[iq addAttributeWithName:#"type" stringValue:#"get"];
DDXMLElement *query = [DDXMLElement elementWithName:#"vCard" xmlns:#"vcard-temp"];
[iq addChild:query];
[_xmppStream sendElement:iq];
Where sender is XMPPJID of the searched user.
XMPPIQ is successfully sended and debugger enter in method:
- (XMPPIQ *)xmppStream:(XMPPStream *)sender willReceiveIQ:(XMPPIQ *)iq;
If I print iq I've:
<iq xmlns="jabber:client" type="result" id="v1" to=<MYJID> >
<vCard xmlns="vcard-temp"/>
</iq>

I'm trying to search an NSArray for a string, and none of my researched methods are working

I'm using Parse and I'm retrieving a class from the data browser titled: "usernames".
I get all the objects in the class, and store them in an array. I then want to search the array for a username, so that the user may login. I will do the same for the password. Here's my code:
- (IBAction)login:(id)sender
{
if ([usernameLogin.stringValue isEqualTo:#""] || [passwordLogin.stringValue isEqualTo:#""]) {
NSBeginAlertSheet(#"Error", #"OK", nil, nil, self.window, self, #selector(sheetDidEnd:resultCode:contextInfo:), NULL, NULL, #"Please fill in all fields.");
}
/* retrieve user from parse db */
PFQuery *usernameQuery = [PFQuery queryWithClassName:#"usernames"];
[usernameQuery findObjectsInBackgroundWithBlock:^(NSArray *usernames, NSError *error) {
NSString *userString = [NSString stringWithFormat:#"%#", usernameLogin.stringValue];
NSLog(#"USERS:\n %#", usernames);
int i;
for (i = 0; i < [usernames count]; i++) {
NSString *userFind = [usernames objectAtIndex:i];
if ([userString isEqualToString:userFind]) {
NSLog(#"FOUND!!!");
}
}
/*
if ([usernames indexOfObject:usernameLogin.stringValue]) {
NSLog(#"User: '%#' was found successfully!", usernameLogin.stringValue);
} else {
NSLog(#"User: '%#' doesn't exist in database, or password was incorrect!", usernameLogin.stringValue);
}
*/
}];
gameCont = [[CSGameController alloc] initWithWindowNibName:#"CSGameController"];
[gameCont showWindow:self];
[gameCont.window makeKeyAndOrderFront:nil];
_window.isVisible = false;
}
Can anyone explain what I'm doing wrong? I'm searching the database to see if the entered user exists. I setup a test user, and it still says it doesn't exist. Thanks so much!
Added:
int i;
for (i = 0; i < [usernames count]; i++) {
NSString *userFind = [usernames objectAtIndex:i];
NSLog(#"UserFind class = %#, value = %#", [userFind class], userFind);
}
Output:
[2438:303] UserFind class = PFObject, value = <usernames:kx7aG2xfkX:(null)> {
username = ryan;
}
It seems you're trying to do a lot of things here that just don't make sense. Please consider reading the Parse iOS Guide. All PFQueries return PFObjects. PFObjects are in many ways like NSDictionaries; they are a single record in a database and can be fetched or stored.
A PFQuery always returns one or more PFObjects. A PFQuery's results should almost always be scopable to be immediately useful. In this example, the equals condition could have been articulated with -[PFQuery whereKey:equalTo:]. It is much faster to let Parse do the search for you. This also lets you create UI powered by the query's results via PFQueryTableViewController.
Finally, please please please don't make your own login code. Your current code is easily hacked to not only allow anyone to log in as anyone, but to learn anyone's password as well. Use the built-in PFUser class for user accounts. It handles secure login, offline caching of credentials, password resets, email verification, you can let users log in with their Facebook or twitter accounts in addition to username/password, and Parse has built-in view controllers for logging in and creating accounts of PFUsers. PFUsers are also the way to secure your data; a PFACL is an Access Control List that lets you decide which PFUsers can read or write data.
The wrong thing here that you are trying to use isEqualToString: with userFind, which is PFObject.
Try comparing with its username property:
...
for (PFObject *aUsername in usernames)
{
NSString *userFind = [aUsername objectForKey:#"username"];
if ([userString isEqualToString:userFind]) {
NSLog(#"FOUND!!!");
}
}
Problem solved: I used Parse's User class. They have pre-existing methods for registering users, like I was trying to do here in my own classes. Their methods for registering are:
PFUser *user = [PFUser user];
user.email = emailField.stringValue;
user.username = usernameField.stringValue;
user.password = passwordField.stringValue;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

send message API error

I am sending send message request with XML bodyfrom my iphone application
<mailbox-item><recipients><recipient><person path='/people/93619553' /></recipient><recipient><person path='/people/116008244' /></recipient><recipient><person path='/people/96885725' /></recipient></recipients><subject>Message from butterfli</subject><body>Aasd</body></mailbox-item>
But getting this error
++ LinkedIn engine reports failure for connection 3CD3052A-7061-4EA0-8863-5584270B9177
The operation couldn’t be completed. (HTTP error 404.)
Code is
- (RDLinkedInConnectionID *)sendMessage:(NSDictionary *)shareDict {
NSURL* url = [NSURL URLWithString:[kAPIBaseURL stringByAppendingString:#"/v1/people/~/mailbox"]];
NSString *xmlStr = #"<mailbox-item><recipients>";
NSArray *toIdArray = [[shareDict objectForKey:#"privacy"] componentsSeparatedByString:#","];
for (int l=0; l<[toIdArray count]; l++) {
xmlStr = [xmlStr stringByAppendingString:[NSString stringWithFormat:#"<recipient><person path='/people/%#' /></recipient>",
[toIdArray objectAtIndex:l]]];
}
xmlStr = [xmlStr stringByAppendingString:[NSString stringWithFormat:#"</recipients><subject>%#</subject><body>%#</body></mailbox-item>",
#"Message from butterfli",[shareDict objectForKey:#"text_message"]]];
[NSString stringWithFormat:#"<share><comment>%#</comment><content><submitted-url>%#</submitted-url></content><visibility><code>anyone</code></visibility></share>",
[shareDict objectForKey:#"link_msg"],[shareDict objectForKey:#"link"]];
NSData *body = [xmlStr dataUsingEncoding:NSUTF8StringEncoding];
NSLog(#"xmlStr..%#",xmlStr);
return [self sendAPIRequestWithURL:url HTTPMethod:#"POST" body:body];
}
Amit Battan
its not a closed issue before it...
But now the solution is
its done...
Before it I am hardcoded the user id which is shown in the URL of user profile on Web.
But its working ok with id of user which is coming through API ..
But not getting why linkedin user different ids??
as
LinkedIn use unique user IDs for each user/application combination to protect user's privacy. Only the application which originally requested (and got) authentication from the member can use that token to retrieve further information.
http://developer.linkedin.com/thread/3044