summaryrefslogtreecommitdiff
path: root/Juick/Model/User.m
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-08-28 21:03:22 +0300
committerGravatar Vitaly Takmazov2016-08-28 21:03:22 +0300
commit188d8e4ea870d1a6c8edd5a9b323742804badeba (patch)
tree071067f7189a6474d49abb952b1b04b820985b7a /Juick/Model/User.m
parenta74588083c4950e9237dff7a84ccdd129b72c950 (diff)
project cleanup
Diffstat (limited to 'Juick/Model/User.m')
-rw-r--r--Juick/Model/User.m49
1 files changed, 49 insertions, 0 deletions
diff --git a/Juick/Model/User.m b/Juick/Model/User.m
new file mode 100644
index 0000000..f4b1e00
--- /dev/null
+++ b/Juick/Model/User.m
@@ -0,0 +1,49 @@
+//
+// User.m
+// Juick
+//
+// Created by Vitaly on 01.02.14.
+// Copyright (c) 2014 com.juick. All rights reserved.
+//
+
+#import "User.h"
+
+
+@implementation User
+
++(BOOL) isAuthenticated {
+ return [[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] != nil;
+}
+
++(void) throwUnableToLogin {
+ SIAlertView *alert = [[SIAlertView alloc] initWithTitle:@"Error" andMessage:@"Unable to login, check username/password, or network connectivity"];
+ [alert addButtonWithTitle:@"OK" type:SIAlertViewButtonTypeCancel handler:^(SIAlertView *alertView) {
+ // <#code#>
+ }];
+ [alert show];
+}
+
++(void) checkIsValid:(void (^)(BOOL))callback {
+ AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
+ [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.username"] password:[[PDKeychainBindings sharedKeychainBindings] stringForKey:@"com.juick.password"]];
+ [manager POST:@"/post" parameters:nil progress:nil success:nil failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
+ NSInteger statusCode = ((NSHTTPURLResponse *)task.response).statusCode;
+ if (statusCode == 400) {
+ callback(YES);
+ } else {
+ [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:nil password:nil];
+ callback(NO);
+ }
+ }];}
+
++(void) get:(NSString *) name callback:(void(^)(User *))callback {
+ AFHTTPSessionManager *manager = [APIClient sharedClient].manager;
+ NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:name, @"uname", nil];
+ [manager GET:@"/users" parameters:params progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
+ callback([User yy_modelWithJSON:[(NSArray *)responseObject firstObject]]);
+ } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
+ callback(nil);
+ }];
+}
+
+@end