- //
- // LoginViewController.m
- // VitalSigns
- //
- // Created by ehealth on 10-08-10.
- // Copyright 2010 __MyCompanyName__. All rights reserved.
- //
- #import "LoginViewController.h"
- #import "ManagedObjectContextSource.h"
- #import "Nurse.h"
- #import "Patient.h"
- #import "ServerConnectionsController.h"
- @interface LoginViewController()
- - (void)getPatientList;
- @end
- @implementation LoginViewController
- @synthesize userName;
- @synthesize userPassword;
- @synthesize loginButton;
- @synthesize loginIndicator;
- @synthesize delegate;
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad {
- [super viewDidLoad];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(loginDidFail:)
- name:@"badLoginCredentials"
- object:nil ];
- [userName becomeFirstResponder];
- }
- - (void)loginDidFail:(NSNotification *)notification {
- NSLog(@"Login did fail");
- }
- - (IBAction)loginButtonPressed: (id) sender {
- loginIndicator.hidden = FALSE;
- [loginIndicator startAnimating];
- loginButton.enabled = FALSE;
- [self getPatientList];
- [self.delegate loginViewControllerDidFinish:self];
- }
- - (void)createNurseWithId:(NSString *) nurseID {
- Nurse *nurse = [NSEntityDescription insertNewObjectForEntityForName: @"Nurse"
- inManagedObjectContext: [[ManagedObjectContextSource sharedContextSource] managedObjectContext]];
- nurse.nurseID = userName.text;
- // Commit edits
- NSError *error;
- NSAssert1([[[ManagedObjectContextSource sharedContextSource] managedObjectContext] save:&error], @"Error saving nurse ID: %@", error);
- //Sanity check
- NSLog(@"nurse ID: %@",nurse.nurseID);
- }
- //TODO should be else where
- - (void)getPatientList {
- //get the patient list from the server
- NSString *username = userName.text;
- NSString *password = userPassword.text;
- [[ServerConnectionsController sharedServerConnections] authenticateWithUserID:username andPassword:password];
- [[ServerConnectionsController sharedServerConnections] getPatientList];
- }
- @end