mirror of
https://github.com/wahyd4/libr-ios.git
synced 2026-08-09 05:06:46 +10:00
81 lines
2.5 KiB
Swift
81 lines
2.5 KiB
Swift
//
|
|
// LogupViewController.swift
|
|
// librx
|
|
//
|
|
// Created by Yunlong Zheng on 15/10/27.
|
|
// Copyright © 2015年 librx. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import SwiftColors
|
|
|
|
class LogupViewController: UIViewController {
|
|
|
|
@IBOutlet weak var passwordTextField: UITextField!
|
|
@IBOutlet weak var signupButton: UIButton!
|
|
@IBOutlet weak var backButton: UIButton!
|
|
@IBOutlet weak var emailTextField: UITextField!
|
|
|
|
|
|
func alert(message: String) {
|
|
let alc = UIAlertController(title: message, message: nil, preferredStyle: UIAlertControllerStyle.Alert)
|
|
alc.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Cancel, handler: nil))
|
|
self.presentViewController(alc, animated: true, completion: nil)
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
self.passwordTextField.secureTextEntry = true
|
|
self.signupButton.layer.borderWidth = 1
|
|
self.signupButton.layer.borderColor = UIColor(hexString: "#3FB5A3")?.CGColor
|
|
self.signupButton.tintColor = UIColor(hexString: "#3FB5A3")
|
|
|
|
self.signupButton.layer.cornerRadius = 5
|
|
self.signupButton.clipsToBounds = true
|
|
|
|
self.backButton.layer.cornerRadius = self.backButton.frame.width / 2
|
|
self.backButton.clipsToBounds = true
|
|
self.backButton.layer.borderWidth = 1
|
|
self.backButton.layer.borderColor=UIColor(hexString: "#3FB5A3")?.CGColor
|
|
self.backButton.tintColor = UIColor(hexString: "#3FB5A3")
|
|
self.backButton.backgroundColor = UIColor(hexString: "#3FB5A3")
|
|
|
|
self.emailTextField.delegate = self
|
|
self.passwordTextField.delegate = self
|
|
|
|
|
|
}
|
|
|
|
@IBAction func sigupBtnPressed(sender: AnyObject) {
|
|
|
|
let username: String = emailTextField.text!
|
|
let password: String = passwordTextField.text!
|
|
|
|
LibrxService.signUp(username, password: password) { (user) -> () in
|
|
|
|
if let _user = user {
|
|
LocalStore.setAccessToken(_user.token)
|
|
LocalStore.setAccessUserId(_user.id)
|
|
self.dismissViewControllerAnimated(true, completion: nil)
|
|
}else {
|
|
self.alert(NSLocalizedString("登录失败了,请稍候再试", comment:"for login error"))
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
extension LogupViewController:UITextFieldDelegate{
|
|
|
|
func textFieldShouldReturn(textField: UITextField) -> Bool {
|
|
|
|
self.view.endEditing(true)
|
|
return false
|
|
|
|
}
|
|
|
|
}
|