Commit cdb5fa4f by lee

auto login|fix bug

parent 4141588f
......@@ -712,8 +712,8 @@ static NSString *const passwordTest = @"9e84aae218c57cdf0762763c4cf5a651";
- (NSURLSessionDataTask *)getHomeDataWithSuccess:(void (^)(NSURLSessionDataTask *, KWMHomeDataResult *))success failure:(void (^)(NSURLSessionDataTask *, NSError *))failure {
NSInteger st = [[NSDate date] timeIntervalSince1970];
st = st - st % 86400 - 28800;
NSString *apiPath = [NSString stringWithFormat:@"https://ogbgohpla.qnssl.com/App.Home.json?%ld",st];
// st = st - st % 86400 - 28800;
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];
}
......
......@@ -25,6 +25,8 @@
@property (nonatomic, strong) KWMCustomsClearance *customsClearance;
@property (nonatomic, strong) BUYClient *client;
@property (nonatomic, strong) BUYCustomer *customer;
@property (nonatomic, strong) NSArray *tags;
......@@ -39,6 +41,8 @@
- (NSDecimalNumber *)exchangeRate;
- (void) requestTags;
- (void) login;
- (void (^)(NSURLSessionDataTask *, KWMRequestResult *))getLoginSuccessCallback:(void (^)(NSURLSessionDataTask *, KWMRequestResult *))callback;
- (void)saveImageUrl:(NSString *)imageUrl key:(NSString *)key;
......
......@@ -16,6 +16,8 @@
#import "PSPDFAlertView.h"
#import "KWMStringUtil.h"
//#import <Mobile-Buy-SDK/Buy/BUYClient.h>
#import "KWMUserModel.h"
#import <SAMKeychain/SAMKeychain.h>
#define SESSID @"PHPSESSID"
static NSString *kwmKeySessionId = @"sessionId";
......@@ -27,7 +29,6 @@ static NSString *kwmKeySavedAccountPassword = @"savedAccountPassword";
@interface KWMUserDao ()
@property (nonatomic, strong) BUYClient *client;
@end
......@@ -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 {
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
NSString *userJSON = [defaults objectForKey:kwmKeyUser];
......
......@@ -18,6 +18,6 @@
+ (instancetype)shareUser;
+ (void) saveAccountByCredentials:(BUYAccountCredentials *) credentials;
- (void)login;
- (void)logout;
- (void) login;
- (void) logout;
@end
......@@ -17,6 +17,7 @@
#import "KWMSplashView.h"
#import "KWMUserModel.h"
#import "KWMLoginVC.h"
#import "KWMShoppingCart.h"
@interface KWMMainVC ()
......@@ -51,8 +52,13 @@
[defaults setBool:NO forKey:KEY_USER_REGISTER];
[defaults synchronize];
}
[[KWMAPIManager sharedManager] loginWebSuccess:nil failure:nil];
// [[KWMAPIManager sharedManager] loginWebSuccess:nil failure:nil];
[[KWMUserDao shareDao] login];
[[KWMUserDao shareDao] requestTags];
[[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) {
}];
}
- (void)initSplash{
......
......@@ -210,7 +210,10 @@ static NSString *idStr = @"KWMBrandCaramelCell";
total = result.products.total.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];
[self.tbvSearch reloadData];
......
......@@ -26,45 +26,108 @@
+(NSString *)transformTag:(KWMFilter *)filter tag:(NSString *)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;
NSDictionary *mapping = @{
@"Autumn/Winter 2017":@"autumn-winter-2017",
@"Spring/Summer 2017":@"spring-summer-2017",
@"Autumn/Winter 2016":@"autumn-winter-2016",
@"Spring/Summer 2016":@"spring-summer-2016",
@"Autumn/Winter 2015":@"autumn-winter-2015",
@"Girls":@"girls",
@"Boys":@"boys",
@"0 month":@"size-0m",
@"3 month":@"size-3m",
@"6 month":@"size-06m",
@"9 month":@"size-9m",
@"12 month":@"size-12m",
@"18 month":@"size-18m",
@"2 year":@"size-02a",
@"3 year":@"size-03a",
@"4 year":@"size-04a",
@"5 year":@"size-05a",
@"6 year":@"size-06a",
@"7 year":@"size-07a",
@"8 year":@"size-08a",
@"10 year":@"size-10a",
@"12 year":@"size-12a",
@"14 year":@"size-14a",
@"16 year":@"size-16a",
@"18":@"shoe-size-18",
@"19":@"shoe-size-19",
@"20":@"shoe-size-20",
@"21":@"shoe-size-21",
@"22":@"shoe-size-22",
@"23":@"shoe-size-23",
@"24":@"shoe-size-24",
@"25":@"shoe-size-25",
@"26":@"shoe-size-26",
@"27":@"shoe-size-27",
@"28":@"shoe-size-28",
@"29":@"shoe-size-29",
@"30":@"shoe-size-30",
@"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 @@
#import "UIColor+SAMAdditions.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()
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.5.1</string>
<string>1.5.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
......@@ -56,7 +56,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2017072116</string>
<string>2017072414</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<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