FatFractal customer forums



Author Topic: user management  (Read 3899 times)

somchemist

  • Newbie
  • *
  • Posts: 7
    • View Profile
user management
« on: February 27, 2014, 03:12:06 PM »
I would like to add additional fields such as profile picture to the FFUser. I read the documentation here http://fatfractal.com/prod/fyi-user-management-part-i/ and somewhere on that page there is an update that says to use FFUserProtocol (and no FFUser subclassing). Does that mean I need to add the fields I want (such as @property (strong, nonatomic) NSData *imageData) in FFUser.h under the FFUserProtocol? Thank you

jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: user management
« Reply #1 on: February 27, 2014, 04:40:35 PM »
Unoffical response.

There are two approaches to creating custom users.

1) subclass FFUser

Here we simply create a subclass of FFUser, declare our custom properties and the all important thing is to register the subclass with FatFractal

Subclass

Code: [Select]

@import Foundation;

@interface CustomUser : FFUser

@property (nonatomic, strong) NSData * imageData;

@end


Register Subclass

Code: [Select]

FatFractal * ff = [[FatFractal alloc] initWithBaseUrl:@"https://...
       
[ff registerClass:[CustomUser class] forClazz:@"FFUser"]; //Most important step! Do this right after you initialize the FatFractal Instance!


Now all methods that return an FFUser will return an instance of CustomUser.

Feel free to formally declare the additional properties in the FDDL file

Code: [Select]

CREATE OBJECTTYPE FFUser (userName STRING, firstName STRING, lastName STRING, email STRING, active BOOLEAN, authDomain STRING, scriptAuthService STRING, groups GRABBAG /FFUserGroup, notif_ids GRABBAG /FFNotificationID, imageData BYTEARRAY)


2) use FFUserProtocol

This I have no experience with but here's a link

http://fatfractal.com/prod/fyi-user-management-part-i/

Hope this helps

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: user management
« Reply #2 on: February 28, 2014, 12:31:55 PM »
Using FFUserProtocol is optional. Support for this has been added so that you can have your app's User objects work seamlessly with CoreData - i.e. they can subclass NSManagedObject. FFUser, in contrast, extends NSObject.

So you can have
@interface CustomUser: NSManagedObject <FFUserProtocol>
// FFUserProtocol properties
@property (strong, nonatomic) NSString          *guid;
@property (strong, nonatomic) NSString          *userName;
// all your other properties
@property (nonatomic, strong) NSData * imageData
// ... etc
@end

somchemist

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: user management
« Reply #3 on: February 28, 2014, 05:48:54 PM »
Thanks to both of you for the help.
I ended up subclassing the FFUser. Everything seems fine except the image does not get uploaded on the server. I am uploading the profile picture when the user is signing up (in the SignupViewController). I am thinking the view gets dismissed before the picture gets uploaded.. is there save in background block that i can call? here is how I am registering the user and trying to upload the profile picture in /FFUser.
Code: [Select]
- (IBAction)signupButtonPressed:(id)sender {
   
    NSString *fullname = _fullnameTextField.text;
    NSString *username = _usernameTextField.text;
    NSString *email = _emailTextField.text;
    NSString *password = _passwordTextField.text;
   
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = @"Signing up...";
    hud.dimBackground = YES;
    hud.yOffset = -77;
   
    FatFractal *ff = [FatFractal main];
    MyFFUser *newUser = [[MyFFUser alloc] initWithFF:ff];
    newUser.firstName = fullname;
    newUser.userName = username;
    newUser.email = email;
    newUser.imageData = _imageData;
   // newUser.stupidString = @"Stupid String";
   
    [ff registerClass:[MyFFUser class] forClazz:@"FFUser"];
    [ff registerUser:newUser password:password onComplete:^(NSError *mErr, id mObj, NSHTTPURLResponse *mResponse) {
   
        if (mErr) {
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[mErr localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [alert show];
            return;
        } else {
         
            if (mObj) {
             
                [self saveUserCredentialsInKeychain];

                [MBProgressHUD hideHUDForView:self.view animated:YES];

           
                [self dismissViewControllerAnimated:YES completion:^{
                    [self handleSuccessfulSignup];
                }];
            }
        }
    }];   
}

when I click on the profile picture field in the data browser, the file is not there
Code: [Select]
{"result":null,"statusMessage":"No BLOB found at /ff/resources/FFUser/xy0Xk-TQMe9MUwl7eboKJ7/profilePic"}
Thank you

jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: user management
« Reply #4 on: February 28, 2014, 05:57:35 PM »
While I cannot address the blob issue, here's how you upload blobs after the object has been created in the backend.

You can call this method in the onComplete block of the register user.

Code: [Select]

[[FatFractal main] updateBlob:_imageData withMimeType:@"type" forObj:newUser memberName:@"imageData" onComplete:^(NSError *theErr, id theObj, NSHTTPURLResponse *theResponse) {
       
    }];


kevin@fatfractal.com

  • Administrator
  • *****
  • Posts: 56
    • View Profile
Re: user management
« Reply #5 on: February 28, 2014, 09:20:58 PM »
Not exactly sure what is going on, but it looks like you are setting the member "imageData" -

Code: [Select]
newUser.imageData = _imageData;

And yet retrieving "profilePic" from the databrowser -

Code: [Select]
{"result":null,"statusMessage":"No BLOB found at /ff/resources/FFUser/xy0Xk-TQMe9MUwl7eboKJ7/profilePic"}

You mentioned looking at the databrowser to see if the info is there under "profilePic", but it should be under the "imageData" member. Do you know where "profilePic" gets into the picture (pun intended)?

Kevin
« Last Edit: February 28, 2014, 09:24:03 PM by kevin@fatfractal.com »

jonnycools

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
Re: user management
« Reply #6 on: February 28, 2014, 09:25:20 PM »
Interesting

Have you formally declared the new properties in your FDDL file for the FFUser ObjectType?

For example

Code: [Select]

CREATE OBJECTTYPE FFUser (userName STRING, firstName STRING, lastName STRING, email STRING, active BOOLEAN, authDomain STRING, scriptAuthService STRING, groups GRABBAG /FFUserGroup, notif_ids GRABBAG /FFNotificationID, imageData BYTEARRAY)


somchemist

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: user management
« Reply #7 on: March 04, 2014, 12:11:59 PM »
as Kevin pointed out, I was setting imageData and was retrieving profilePic. As a result I updated MyFFuser as below
Code: [Select]
@property (strong, nonatomic) NSData            *profilePic;
@property (strong, nonatomic) FFGeoLocation      *location;


Then in SignupViewController
Code: [Select]
   FatFractal *ff = [FatFractal main];
    MyFFUser *newUser = [[MyFFUser alloc] initWithFF:ff];
    newUser.firstName = firstName;
    newUser.userName = userName;
    newUser.email = email;
    newUser.profilePic = _imageData;
[ff registerClass:[MyFFUser class] forClazz:@"FFUser"];
    [ff registerUser:newUser password:password onComplete:^(NSError *mErr, id mObj, NSHTTPURLResponse *mResponse) {

and Jonnycools yes I declared in my FDDL as below
Code: [Select]
CREATE OBJECTTYPE FFUser (userName STRING, firstName STRING, lastName STRING, email STRING, active BOOLEAN, authDomain STRING, scriptAuthService STRING, groups GRABBAG /FFUserGroup, notif_ids GRABBAG /FFNotificationID, profilePic BYTEARRAY, location GEOLOCATION, stupidString STRING)
and still I am getting
Code: [Select]
{"result":null,"statusMessage":"No BLOB found at /ff/resources/FFUser/xQK2IUKpAD496P6sAorqh5/profilePic"}
Thank you guys for the help.

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: user management
« Reply #8 on: March 04, 2014, 01:47:32 PM »
Ah. OK this is an inconsistency, and an annoying one at that - sorry.

When doing a user register, you need to persist the blob *separately* in a subsequent call, via one of the updateBlob:.... methods


somchemist

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: user management
« Reply #9 on: March 08, 2014, 02:48:42 PM »
Thanks Gary,

JonnyCools suggested I could use
Code: [Select]
[[FatFractal main] updateBlob:_imageData withMimeType:@"type" forObj:newUser memberName:@"imageData" onComplete:^(NSError *theErr, id theObj, NSHTTPURLResponse *theResponse) {
       
    }];

what is withMimeType:@"type"? Thanks

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: user management
« Reply #10 on: March 08, 2014, 08:55:36 PM »
Hey Eric - it's just the mime type of your data - for example "application/octet-stream" or "image/png" or "image/jpeg"


somchemist

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: user management
« Reply #11 on: March 14, 2014, 06:45:31 PM »
Gary Thanks,

If the user wants to update (replace) their profile picture and they are uploading the new picture from the Photo Library , I would not know the type of the image (png, jpeg, etc) in advance.

gkc

  • Administrator
  • *****
  • Posts: 375
    • View Profile
Re: user management
« Reply #12 on: March 14, 2014, 07:00:18 PM »
Not a problem; if you know it's an image, just store as application/octet-stream, iOS figures it out anyway

 

Copyright © FatFractal customer forums