Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package csc200.group8.app.network.requests;
- import java.io.UnsupportedEncodingException;
- import java.net.URLEncoder;
- import java.util.Calendar;
- import csc200.group8.app.model.User;
- import csc200.group8.app.model.StatusCode;
- import csc200.group8.app.model.ReturnedObjectCallBack;
- import csc200.group8.app.model.uiinteraction.CallBack;
- public class CreateUserRequest implements ServerRequest
- {
- private String name;
- private String libraryNumber;
- private String userName;
- private String password;
- private Calendar dob;
- private boolean locationVisible;
- private CallBack callback = null;
- private ReturnedObjectCallBack<User> roCallback = null;
- private boolean complete = false;
- public CreateUserRequest(CallBack callback, String name, String libraryNumber,
- String userName, String password, Calendar dob,
- boolean locationVisible)
- {
- this.name = name;
- this.libraryNumber = libraryNumber;
- this.userName = userName;
- this.password = password;
- this.dob = dob;
- this.locationVisible = locationVisible;
- this.callback = callback;
- }
- public CreateUserRequest(ReturnedObjectCallBack<User> roCallback, String name,
- String libraryNumber, String userName, String password,
- Calendar dob, boolean locationVisible)
- {
- this.name = name;
- this.libraryNumber = libraryNumber;
- this.userName = userName;
- this.password = password;
- this.dob = dob;
- this.locationVisible = locationVisible;
- this.callback = roCallback;
- this.roCallback = roCallback;
- }
- public String getURL()
- {
- int locstat = 0;//Used to encode the locationStatus. 0 = public. 1 = private.
- if(locationVisible == false)
- {
- locstat = 1;
- }
- return URLEncoder.encode("create_user.php?name=" + name + "&lib_no=" + libraryNumber +
- "&username=" + userName + "&password=" + password + "&dob=" + dob.toString()
- + "&location_status=" + locstat + "&access_level=0");
- }
- public boolean isCompleted()
- {
- return complete;
- }
- public void complete(SuccessStatus status, String response)
- {
- //below lines need copy pasting in from somewhere
- User user = new User(response parsing...);
- //I'll add something in here later to submit the created user to the model
- if(status == SuccessStatus.SUCCESS)
- {
- if(rcCallback != null)
- {
- roCallback.setReturnedObject(user);
- }
- callback.notify(StatusCode.SUCCESS);
- }
- else
- {
- callback.notify(StatusCode.NETWORK_FAILURE);
- }
- }
- }
Add Comment
Please, Sign In to add comment