Skip to content

Commit

Permalink
Merge pull request #552 from zapcannon87/master
Browse files Browse the repository at this point in the history
Release v11.6.0
  • Loading branch information
zapcannon87 authored Mar 26, 2019
2 parents d181c5d + d8202f4 commit 4192d0a
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 19 deletions.
9 changes: 9 additions & 0 deletions AVOS/AVOSCloud/User/AVUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ A LeanCloud Framework User Object that is a local representation of a user persi
password:(NSString *)password
block:(AVUserResultBlock)block;

/**
Login by email and password.
@param email The email string.
@param password The password string.
@param block callback.
*/
+ (void)loginWithEmail:(NSString *)email password:(NSString *)password block:(AVUserResultBlock)block;

//phoneNumber + password
/*!
* 使用手机号码和密码登录
Expand Down
25 changes: 14 additions & 11 deletions AVOS/AVOSCloud/User/AVUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,6 @@ - (void)refreshSessionTokenWithBlock:(AVBooleanResultBlock)block {
}];
}

+(NSDictionary *)userParameter:(NSString *)username
password:(NSString *)password
{
NSDictionary * parameters = @{usernameTag: username, passwordTag:password};
return parameters;
}

// MARK: - login with username & password

+ (instancetype)logInWithUsername:(NSString *)username
Expand All @@ -395,7 +388,7 @@ + (instancetype)logInWithUsername:(NSString *)username
error:(NSError **)error
{
__block AVUser * resultUser = nil;
[[self class] logInWithUsername:username password:password block:^(AVUser *user, NSError *error) {
[[self class] logInWithUsername:username email:nil password:password block:^(AVUser *user, NSError *error) {
resultUser = user;
} waitUntilDone:YES error:error];
return resultUser;
Expand All @@ -404,7 +397,7 @@ + (instancetype)logInWithUsername:(NSString *)username
+ (void)logInWithUsernameInBackground:(NSString *)username
password:(NSString *)password
{
[[self class] logInWithUsername:username password:password block:nil waitUntilDone:YES error:nil];
[[self class] logInWithUsername:username email:nil password:password block:nil waitUntilDone:YES error:nil];
}

+ (void)logInWithUsernameInBackground:(NSString *)username
Expand All @@ -423,14 +416,21 @@ + (void)logInWithUsernameInBackground:(NSString *)username
password:(NSString *)password
block:(AVUserResultBlock)block
{
[[self class] logInWithUsername:username password:password block:^(AVUser *user, NSError * error) {
[[self class] logInWithUsername:username email:nil password:password block:^(AVUser *user, NSError * error) {
[AVUtils callUserResultBlock:block user:user error:error];
}
waitUntilDone:NO error:nil];

}

+ (void)loginWithEmail:(NSString *)email password:(NSString *)password block:(AVUserResultBlock)block {
[[self class] logInWithUsername:nil email:email password:password block:^(AVUser * _Nullable user, NSError * _Nullable error) {
[AVUtils callUserResultBlock:block user:user error:error];
} waitUntilDone:false error:nil];
}

+ (BOOL)logInWithUsername:(NSString *)username
email:(NSString *)email
password:(NSString *)password
block:(AVUserResultBlock)block
waitUntilDone:(BOOL)wait
Expand All @@ -440,7 +440,10 @@ + (BOOL)logInWithUsername:(NSString *)username
BOOL __block hasCalledBack = NO;
NSError __block *blockError = nil;

NSDictionary * parameters = [[self class] userParameter:username password:password];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
if (username) { parameters[usernameTag] = username; }
if (email) { parameters[emailTag] = email; }
if (password) { parameters[passwordTag] = password; }
[[AVPaasClient sharedInstance] postObject:@"login" withParameters:parameters block:^(id object, NSError *error) {
AVUser * user = nil;
if (error == nil)
Expand Down
2 changes: 1 addition & 1 deletion AVOS/AVOSCloud/UserAgent.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define SDK_VERSION @"v11.5.2"
#define SDK_VERSION @"v11.6.0"
40 changes: 40 additions & 0 deletions AVOS/AVOSCloudTests/Swift/AVUserTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,44 @@ class AVUser_TestCase: LCTestBase {
})
}

func testLoginByEmail() {
let user = AVUser()
let username = UUID().uuidString.replacingOccurrences(of: "-", with: "")
user.username = username
let password = UUID().uuidString.replacingOccurrences(of: "-", with: "")
user.password = password
let email = "\(UUID().uuidString.replacingOccurrences(of: "-", with: ""))@email.com"
user.email = email

do {
try user.signUpAndThrows()
} catch {
XCTFail("\(error)")
}

let exp1 = expectation(description: "login by email")
AVUser.login(withEmail: email, password: password) { (sameUser, error) in
XCTAssertNotNil(sameUser)
XCTAssertFalse(user === sameUser)
XCTAssertEqual(user.objectId, sameUser?.objectId)
XCTAssertEqual(username, sameUser?.username)
XCTAssertEqual(email, sameUser?.email)
XCTAssertNil(error)
exp1.fulfill()
}
wait(for: [exp1], timeout: 30)

let exp2 = expectation(description: "login by username")
AVUser.logInWithUsername(inBackground: username, password: password) { (sameUser, error) in
XCTAssertNotNil(sameUser)
XCTAssertFalse(user === sameUser)
XCTAssertEqual(user.objectId, sameUser?.objectId)
XCTAssertEqual(username, sameUser?.username)
XCTAssertEqual(email, sameUser?.email)
XCTAssertNil(error)
exp2.fulfill()
}
wait(for: [exp2], timeout: 30)
}

}
2 changes: 1 addition & 1 deletion AVOSCloud.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AVOSCloud'
s.version = '11.5.2'
s.version = '11.6.0'
s.homepage = 'https://leancloud.cn/'
s.summary = 'LeanCloud Objective-C SDK'
s.authors = 'LeanCloud'
Expand Down
2 changes: 1 addition & 1 deletion AVOSCloudIM.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AVOSCloudIM'
s.version = '11.5.2'
s.version = '11.6.0'
s.homepage = 'https://leancloud.cn/'
s.summary = 'LeanCloud IM Objective-C SDK'
s.authors = 'LeanCloud'
Expand Down
2 changes: 1 addition & 1 deletion AVOSCloudLiveQuery.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AVOSCloudLiveQuery'
s.version = '11.5.2'
s.version = '11.6.0'
s.homepage = 'https://leancloud.cn/'
s.summary = 'LeanCloud LiveQuery Objective-C SDK'
s.authors = 'LeanCloud'
Expand Down
8 changes: 4 additions & 4 deletions command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func build() -> Result {
let lines: [String] = (info as! String).components(separatedBy: .newlines)
.map { $0.trimmingCharacters(in: .whitespaces) }
schemes = {
guard var startIndex: Int = lines.index(of: "Schemes:") else { return [] }
guard let endIndex: Int = lines[startIndex...].index(of: "") else { return [] }
guard var startIndex: Int = lines.firstIndex(of: "Schemes:") else { return [] }
guard let endIndex: Int = lines[startIndex...].firstIndex(of: "") else { return [] }
startIndex += 1
guard startIndex < endIndex else { return [] }
let arraySlice: ArraySlice<String> = lines[startIndex..<endIndex].filter {
Expand All @@ -100,8 +100,8 @@ func build() -> Result {
return Array(arraySlice)
}()
buildConfigurations = {
guard var startIndex: Int = lines.index(of: "Build Configurations:") else { return [] }
guard let endIndex: Int = lines[startIndex...].index(of: "") else { return [] }
guard var startIndex: Int = lines.firstIndex(of: "Build Configurations:") else { return [] }
guard let endIndex: Int = lines[startIndex...].firstIndex(of: "") else { return [] }
startIndex += 1
guard startIndex < endIndex else { return [] }
let arraySlice: ArraySlice<String> = lines[startIndex..<endIndex]
Expand Down

0 comments on commit 4192d0a

Please sign in to comment.