Commit cdb5fa4f by lee

auto login|fix bug

parent 4141588f
...@@ -712,8 +712,8 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651"; ...@@ -712,8 +712,8 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
- (NSURLSessionDataTask *)getHomeDataWithSuccess:(void (^)(NSURLSessionDataTask *, KWMHomeDataResult *))success failure:(void (^)(NSURLSessionDataTask *, NSError *))failure { - (NSURLSessionDataTask *)getHomeDataWithSuccess:(void (^)(NSURLSessionDataTask *, KWMHomeDataResult *))success failure:(void (^)(NSURLSessionDataTask *, NSError *))failure {
NSInteger st = [[NSDate date] timeIntervalSince1970]; NSInteger st = [[NSDate date] timeIntervalSince1970];
st = st - st % 86400 - 28800; // st = st - st % 86400 - 28800;
NSString *apiPath = [NSString stringWithFormat:@"https://ogbgohpla.qnssl.com/App.Home.json?%ld",st]; NSString *apiPath = [NSString stringWithFormat:@"https://ogbgohpla.qnssl.com/App.Home.json?st=%ld",st];
return [self startSessionTask:KWMHTTPMethodGET apiPath:apiPath parameters:nil result:[KWMHomeDataResult class] model:nil success:success failure:failure]; return [self startSessionTask:KWMHTTPMethodGET apiPath:apiPath parameters:nil result:[KWMHomeDataResult class] model:nil success:success failure:failure];
} }
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
@property (nonatomic, strong) KWMCustomsClearance *customsClearance; @property (nonatomic, strong) KWMCustomsClearance *customsClearance;
@property (nonatomic, strong) BUYClient *client;
@property (nonatomic, strong) BUYCustomer *customer; @property (nonatomic, strong) BUYCustomer *customer;
@property (nonatomic, strong) NSArray *tags; @property (nonatomic, strong) NSArray *tags;
...@@ -39,6 +41,8 @@ ...@@ -39,6 +41,8 @@
- (NSDecimalNumber *)exchangeRate; - (NSDecimalNumber *)exchangeRate;
- (void) requestTags; - (void) requestTags;
- (void) login;
- (void (^)(NSURLSessionDataTask *, KWMRequestResult *))getLoginSuccessCallback:(void (^)(NSURLSessionDataTask *, KWMRequestResult *))callback; - (void (^)(NSURLSessionDataTask *, KWMRequestResult *))getLoginSuccessCallback:(void (^)(NSURLSessionDataTask *, KWMRequestResult *))callback;
- (void)saveImageUrl:(NSString *)imageUrl key:(NSString *)key; - (void)saveImageUrl:(NSString *)imageUrl key:(NSString *)key;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#import "PSPDFAlertView.h" #import "PSPDFAlertView.h"
#import "KWMStringUtil.h" #import "KWMStringUtil.h"
//#import <Mobile-Buy-SDK/Buy/BUYClient.h> //#import <Mobile-Buy-SDK/Buy/BUYClient.h>
#import "KWMUserModel.h"
#import <SAMKeychain/SAMKeychain.h>
#define SESSID @"PHPSESSID" #define SESSID @"PHPSESSID"
static NSString *kwmKeySessionId = @"sessionId"; static NSString *kwmKeySessionId = @"sessionId";
...@@ -27,7 +29,6 @@ static NSString *kwmKeySavedAccountPassword = @"savedAccountPassword"; ...@@ -27,7 +29,6 @@ static NSString *kwmKeySavedAccountPassword = @"savedAccountPassword";
@interface KWMUserDao () @interface KWMUserDao ()
@property (nonatomic, strong) BUYClient *client;
@end @end
...@@ -125,6 +126,53 @@ static NSString *kwmKeySavedAccountPassword = @"savedAccountPassword"; ...@@ -125,6 +126,53 @@ static NSString *kwmKeySavedAccountPassword = @"savedAccountPassword";
} }
} }
- (void)login {
KWMUserModel *user= [KWMUserModel shareUser];
NSString *account = user.email;
NSString *password = user.password;
if (!password) {
password = [SAMKeychain passwordForService:@"cemarose.account" account:account];
}
if (!(account && password)) {
return;
}
NSArray *items = @[
[BUYAccountCredentialItem itemWithEmail:account],
[BUYAccountCredentialItem itemWithPassword:password],
];
BUYAccountCredentials *credentials = [BUYAccountCredentials credentialsWithItems:items];
// [weakSelf requestLoginAPI:credentials];
[self.client loginCustomerWithCredentials:credentials callback:^(BUYCustomer * _Nullable customer, BUYCustomerToken * _Nullable token, NSError * _Nullable error) {
if (customer && token && !error) {
[KWMUserModel saveAccountByCredentials:credentials];
_customer = customer;
// _token = token;
// _userModel.customerJSON = customer.JSONDictionary;
// _userModel.tokenJSON = token.JSONDictionary;
//异步保存数据
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// [self saveData];
// [_userModel login];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:_customer.JSONDictionary forKey:@"customer"];
[defaults setObject:token.JSONDictionary forKey:@"token"];
[defaults synchronize];
[[KWMAPIManager sharedManager] loginWebSuccess:nil failure:nil];
});
}else{
NSLog(@"requestLoginAPI error: %@",error);
[user logout];
[self logout];
}
}];
}
- (KWMUser *)loginUser { - (KWMUser *)loginUser {
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults]; NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
NSString *userJSON = [defaults objectForKey:kwmKeyUser]; NSString *userJSON = [defaults objectForKey:kwmKeyUser];
......
...@@ -18,6 +18,6 @@ ...@@ -18,6 +18,6 @@
+ (instancetype)shareUser; + (instancetype)shareUser;
+ (void) saveAccountByCredentials:(BUYAccountCredentials *) credentials; + (void) saveAccountByCredentials:(BUYAccountCredentials *) credentials;
- (void)login; - (void) login;
- (void)logout; - (void) logout;
@end @end
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#import "KWMSplashView.h" #import "KWMSplashView.h"
#import "KWMUserModel.h" #import "KWMUserModel.h"
#import "KWMLoginVC.h" #import "KWMLoginVC.h"
#import "KWMShoppingCart.h"
@interface KWMMainVC () @interface KWMMainVC ()
...@@ -51,8 +52,13 @@ ...@@ -51,8 +52,13 @@
[defaults setBool:NO forKey:KEY_USER_REGISTER]; [defaults setBool:NO forKey:KEY_USER_REGISTER];
[defaults synchronize]; [defaults synchronize];
} }
[[KWMAPIManager sharedManager] loginWebSuccess:nil failure:nil]; // [[KWMAPIManager sharedManager] loginWebSuccess:nil failure:nil];
[[KWMUserDao shareDao] login];
[[KWMUserDao shareDao] requestTags]; [[KWMUserDao shareDao] requestTags];
[[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) {
}];
} }
- (void)initSplash{ - (void)initSplash{
......
...@@ -210,7 +210,10 @@ static NSString *idStr = @"KWMBrandCaramelCell"; ...@@ -210,7 +210,10 @@ static NSString *idStr = @"KWMBrandCaramelCell";
total = result.products.total.integerValue; total = result.products.total.integerValue;
endPage = result.products.lastPage.integerValue; endPage = result.products.lastPage.integerValue;
[weakSelf appendDataList:result.productList setPage:tagetPage]; NSArray *products = [result.productList rx_filterWithBlock:^BOOL(BUYProduct *each) {
return each.availableValue;
}];
[weakSelf appendDataList:products setPage:tagetPage];
_vSearchFB.lbGoodsNum.text = [NSString stringWithFormat:@"%lu商品",(unsigned long)total]; _vSearchFB.lbGoodsNum.text = [NSString stringWithFormat:@"%lu商品",(unsigned long)total];
[self.tbvSearch reloadData]; [self.tbvSearch reloadData];
......
...@@ -26,45 +26,108 @@ ...@@ -26,45 +26,108 @@
+(NSString *)transformTag:(KWMFilter *)filter tag:(NSString *)tag{ +(NSString *)transformTag:(KWMFilter *)filter tag:(NSString *)tag{
NSString *mTag = [tag copy]; NSDictionary *mapping = @{
@"Autumn/Winter 2017":@"autumn-winter-2017",
//"Spring/Summer 2017" => Spring-Summer-2017 @"Spring/Summer 2017":@"spring-summer-2017",
if([filter.group isEqualToString:@"SEASON"]){ @"Autumn/Winter 2016":@"autumn-winter-2016",
mTag = [mTag stringByReplacingOccurrencesOfString:@"/" withString:@"-"]; @"Spring/Summer 2016":@"spring-summer-2016",
return [tag stringByReplacingOccurrencesOfString:@" " withString:@"-"]; @"Autumn/Winter 2015":@"autumn-winter-2015",
} @"Girls":@"girls",
@"Boys":@"boys",
//1 month=> size-01m @"0 month":@"size-0m",
else if([filter.group isEqualToString:@"SIZE"]){ @"3 month":@"size-3m",
//不合规则的区别待遇 @"6 month":@"size-06m",
if([tag isEqualToString:@"0 month"]){ @"9 month":@"size-9m",
return @"size-0m"; @"12 month":@"size-12m",
}else if([tag isEqualToString:@"3 month"]){ @"18 month":@"size-18m",
return @"size-3m"; @"2 year":@"size-02a",
}else if([tag isEqualToString:@"3 month"]){ @"3 year":@"size-03a",
return @"size-9m"; @"4 year":@"size-04a",
} @"5 year":@"size-05a",
@"6 year":@"size-06a",
NSString *numberString = [self getNumberString:tag]; @"7 year":@"size-07a",
numberString = numberString.length == 1 ? [NSString stringWithFormat:@"0%@",numberString]:numberString; @"8 year":@"size-08a",
if([tag rangeOfString:@"year"].location == NSNotFound){ @"10 year":@"size-10a",
return [NSString stringWithFormat:@"size-%@m",numberString]; @"12 year":@"size-12a",
}else{ @"14 year":@"size-14a",
return [NSString stringWithFormat:@"size-%@a",numberString]; @"16 year":@"size-16a",
} @"18":@"shoe-size-18",
} @"19":@"shoe-size-19",
@"20":@"shoe-size-20",
//12 => shoe-size-1 @"21":@"shoe-size-21",
else if([filter.group isEqualToString:@"Shoe Size"]){ @"22":@"shoe-size-22",
return [NSString stringWithFormat:@"shoe-size-%@",tag]; @"23":@"shoe-size-23",
} @"24":@"shoe-size-24",
@"25":@"shoe-size-25",
//Trousers & Shorts => trousers-shorts @"26":@"shoe-size-26",
else if([filter.group isEqualToString:@"PRODUCT TYPE"]){ @"27":@"shoe-size-27",
return [KWMStringUtil deleteOtherCharExceptLetterWithLine:tag]; @"28":@"shoe-size-28",
} @"29":@"shoe-size-29",
@"30":@"shoe-size-30",
return mTag; @"31":@"shoe-size-31",
@"32":@"shoe-size-32",
@"33":@"shoe-size-33",
@"34":@"shoe-size-34",
@"35":@"shoe-size-35",
@"37":@"shoe-size-37",
@"38":@"shoe-size-38",
@"39":@"shoe-size-39",
@"Accessories":@"accessories",
@"Babysuits":@"babysuits",
@"Coats & Jackets":@"coats-jackets",
@"Dresses":@"dresses",
@"Leggings":@"leggings",
@"Raincoat":@"raincoat",
@"Sets":@"sets",
@"Shoes":@"shoes",
@"Skirts":@"skirts",
@"Swimwear":@"swimwear",
@"Tights":@"tights",
@"Tops":@"tops",
@"Toys":@"toys",
@"Trousers & Shorts":@"trousers-shorts",
@"Underwear":@"underwear",
};
return mapping[tag];
// NSString *mTag = [tag copy];
//
// //"Spring/Summer 2017" => Spring-Summer-2017
// if([filter.group isEqualToString:@"SEASON"]){
// mTag = [mTag stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
// return [tag stringByReplacingOccurrencesOfString:@" " withString:@"-"];
// }
//
// //1 month=> size-01m
// else if([filter.group isEqualToString:@"SIZE"]){
// //不合规则的区别待遇
// if([tag isEqualToString:@"0 month"]){
// return @"size-0m";
// }else if([tag isEqualToString:@"3 month"]){
// return @"size-3m";
// }else if([tag isEqualToString:@"3 month"]){
// return @"size-9m";
// }
//
// NSString *numberString = [self getNumberString:tag];
// numberString = numberString.length == 1 ? [NSString stringWithFormat:@"0%@",numberString]:numberString;
// if([tag rangeOfString:@"year"].location == NSNotFound){
// return [NSString stringWithFormat:@"size-%@m",numberString];
// }else{
// return [NSString stringWithFormat:@"size-%@a",numberString];
// }
// }
//
// //12 => shoe-size-1
// else if([filter.group isEqualToString:@"Shoe Size"]){
// return [NSString stringWithFormat:@"shoe-size-%@",tag];
// }
//
// //Trousers & Shorts => trousers-shorts
// else if([filter.group isEqualToString:@"PRODUCT TYPE"]){
// return [KWMStringUtil deleteOtherCharExceptLetterWithLine:tag];
// }
//
// return mTag;
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#import "UIColor+SAMAdditions.h" #import "UIColor+SAMAdditions.h"
#import "KWMStringUtil.h" #import "KWMStringUtil.h"
static NSString *filterDataString = @"[{\"group\":\"SEASON\",\"tags\":[\"Spring/Summer 2017\",\"Autumn/Winter 2016\",\"Spring/Summer 2016\",\"Autumn/Winter 2015\"]},{\"group\":\"GENDER\",\"tags\":[\"Girls\",\"Boys\"]},{\"group\":\"SIZE\",\"tags\":[\"0 month\",\"3 month\",\"6 month\",\"9 month\",\"12 month\",\"18 month\",\"2 year\",\"3 year\",\"4 year\",\"5 year\",\"6 year\",\"7 year\",\"8 year\",\"10 year\",\"12 year\",\"14 year\",\"16 year\"]},{\"group\":\"Shoe Size\",\"tags\":[\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\",\"26\",\"27\",\"28\",\"29\",\"30\",\"31\",\"32\",\"33\",\"34\",\"35\",\"37\",\"38\",\"39\"]},{\"group\":\"PRODUCT TYPE\",\"tags\":[\"Accessories\",\"Babysuits\",\"Coats & Jackets\",\"Dresses\",\"Leggings\",\"Raincoat\",\"Sets\",\"Shoes\",\"Skirts\",\"Swimwear\",\"Tights\",\"Tops\",\"Toys\",\"Trousers & Shorts\",\"Underwear\"]}]"; static NSString *filterDataString = @"[{\"group\":\"SEASON\",\"tags\":[\"Autumn/Winter 2017\",\"Spring/Summer 2017\",\"Autumn/Winter 2016\",\"Spring/Summer 2016\",\"Autumn/Winter 2015\"]},{\"group\":\"GENDER\",\"tags\":[\"Girls\",\"Boys\"]},{\"group\":\"SIZE\",\"tags\":[\"0 month\",\"3 month\",\"6 month\",\"9 month\",\"12 month\",\"18 month\",\"2 year\",\"3 year\",\"4 year\",\"5 year\",\"6 year\",\"7 year\",\"8 year\",\"10 year\",\"12 year\",\"14 year\",\"16 year\"]},{\"group\":\"Shoe Size\",\"tags\":[\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"24\",\"25\",\"26\",\"27\",\"28\",\"29\",\"30\",\"31\",\"32\",\"33\",\"34\",\"35\",\"37\",\"38\",\"39\"]},{\"group\":\"PRODUCT TYPE\",\"tags\":[\"Accessories\",\"Babysuits\",\"Coats & Jackets\",\"Dresses\",\"Leggings\",\"Raincoat\",\"Sets\",\"Shoes\",\"Skirts\",\"Swimwear\",\"Tights\",\"Tops\",\"Toys\",\"Trousers & Shorts\",\"Underwear\"]}]";
@interface KWMFilterView() @interface KWMFilterView()
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.5.1</string> <string>1.5.2</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleURLTypes</key> <key>CFBundleURLTypes</key>
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
</dict> </dict>
</array> </array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>2017072116</string> <string>2017072414</string>
<key>ITSAppUsesNonExemptEncryption</key> <key>ITSAppUsesNonExemptEncryption</key>
<false/> <false/>
<key>LSApplicationQueriesSchemes</key> <key>LSApplicationQueriesSchemes</key>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment