<commit_before>//
//  PcHTTPService+Login.swift
//  Train12306
//
//  Created by fancymax on 15/11/7.
//  Copyright © 2015年 fancy. All rights reserved.
//

import JavaScriptCore
import Foundation
import Alamofire
import PromiseKit
import SwiftyJSON

extension Service {
    
// MARK: - Request Flow
    func preLoginFlow(success:@escaping (NSImage)->Void,failure:@escaping (NSError)->Void){
        let cookie1 = HTTPCookie(properties: [.name:"RAIL_DEVICEID",.domain:"kyfw.12306.cn",.value:"<KEY>",.path:"/"])
        let cookie2 = HTTPCookie(properties: [.name:"RAIL_EXPIRATION",.domain:"kyfw.12306.cn",.value:"1516238840716",.path:"/"])
        Service.Manager.session.configuration.httpCookieStorage?.setCookie(cookie1!)
        Service.Manager.session.configuration.httpCookieStorage?.setCookie(cookie2!)
    
        loginInit().then{(dynamicJs) -> Promise<Void> in
            return self.requestDynamicJs(dynamicJs, referHeader: ["refer": "https://kyfw.12306.cn/otn/login/init"])
        }.then{_ -> Promise<NSImage> in
            return self.getPassCodeNewForLogin()
        }.then{ image in
            success(image)
        }.catch { error in
            failure(error as NSError)
        }
    }
    
    func loginFlow(user:String,passWord:String,randCodeStr:String,success:@escaping ()->Void,failure:@escaping (NSError)->Void){
        after(interval: 2).then{
            self.checkRandCodeForLogin(randCodeStr)
        }.then{() -> Promise<Void> in
            return self.loginUserWith(user, passWord: passWord, randCodeStr: randCodeStr)
        }.then{ () -> Promise<(Bool,String)> in
            return self.checkUAM()
        }.then{ (hasLogin,tk) -> Promise<Bool> in
            return self.uampassport(tk: tk)
        }.then{ (_) -> Promise<Void> in
            return self.initMy12306()
        }.then{ () -> Promise<Void> in
            return self.getPassengerDTOs(isSubmit: false)
        }.then{_ in
            success()<commit_msg>fix: 临时处理DeviceID<commit_after>//
//  PcHTTPService+Login.swift
//  Train12306
//
//  Created by fancymax on 15/11/7.
//  Copyright © 2015年 fancy. All rights reserved.
//

import JavaScriptCore
import Foundation
import Alamofire
import PromiseKit
import SwiftyJSON

extension Service {
    
// MARK: - Request Flow
    func preLoginFlow(success:@escaping (NSImage)->Void,failure:@escaping (NSError)->Void){
        let cookie1 = HTTPCookie(properties: [.name:"RAIL_DEVICEID",.domain:"kyfw.12306.cn",.value:"CyeQGv5X_Y9BsIIkxXGf8s_wPmVs2yH4idlQo3d4KxgeY10nAnXWcm72qwxLLd_xqQm-v8UaFAVL7elDx_KFZw1FN3MkwJcbQAGtPIFEWfWPsdsOr5_jgjV-HSn7t-2u2fZgGrTOSCpfoYMOF41I1qWmNkGkObIX",.path:"/"])
        let cookie2 = HTTPCookie(properties: [.name:"RAIL_EXPIRATION",.domain:"kyfw.12306.cn",.value:"1516426090658",.path:"/"])
        Service.Manager.session.configuration.httpCookieStorage?.setCookie(cookie1!)
        Service.Manager.session.configuration.httpCookieStorage?.setCookie(cookie2!)
    
        loginInit().then{(dynamicJs) -> Promise<Void> in
            return self.requestDynamicJs(dynamicJs, referHeader: ["refer": "https://kyfw.12306.cn/otn/login/init"])
        }.then{_ -> Promise<NSImage> in
            return self.getPassCodeNewForLogin()
        }.then{ image in
            success(image)
        }.catch { error in
            failure(error as NSError)
        }
    }
    
    func loginFlow(user:String,passWord:String,randCodeStr:String,success:@escaping ()->Void,failure:@escaping (NSError)->Void){
        after(interval: 2).then{
            self.checkRandCodeForLogin(randCodeStr)
        }.then{() -> Promise<Void> in
            return self.loginUserWith(user, passWord: passWord, randCodeStr: randCodeStr)
        }.then{ () -> Promise<(Bool,String)> in
            return self.checkUAM()
        }.then{ (hasLogin,tk) -> Promise<Bool> in
            return self.uampassport(tk: tk)
        }.then{ (_) -> Promise<Void> in
            return self.initMy12306()
        }.then{ () -> Promise<Void> in
            return self.getPassengerDTOs(isSubmit: false)
        }.then{_ in
            success()
{'fraction_non_alphanumeric': 0.137221269296741, 'fraction_numerical': 0.030874785591766724, 'mean_word_length': 2.9902248289345064, 'pattern_counts': {'":': 2, '<': 18, '<?xml version=': 0, '>': 40, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '396805', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1354, 'n_words': 218}