git.iko.soy/dashared/GDproject
on master help sign in
Alerts and more
commit5ca9bbb7f8657de3a0926bcaf17ba7b37c0fb84b authorDarya Rednikina <rednikina.com@yandex.ru> dateMon 13 May 2019, 12:30 (7 years ago) parent525bc7c
15 files changed+256−91
GDproject/Controller/ News and channels/ChannelController.swift+1−1 GDproject/Controller/ News and channels/ChannelListController.swift+1−1 GDproject/Controller/ News and channels/ChannelViewController.swift+5−1 GDproject/Controller/ News and channels/FullPostController.swift+1−18 GDproject/Controller/ News and channels/NewPostViewController.swift+2−1 GDproject/Controller/ News and channels/NewsController.swift+1 GDproject/Controller/Coordinators/ProfileCoordinator.swift+15−13 GDproject/Controller/Log In/RegisterTableViewController.swift+52−11 GDproject/Controller/Messages/Dialog/DialogViewController.swift+2−1 GDproject/Controller/Messages/MessagesViewController.swift+2−2 GDproject/Controller/Profile/BasicInfoController.swift+16−11 GDproject/Controller/Profile/InfoCell.swift+2−1 GDproject/Controller/Profile/ProfileViewController.swift+63−21 GDproject/Extentions.swift+30 GDproject/Simple model/Model.swift+63−9
GDproject/Controller/ News and channels/ChannelController.swift+1−1
@@ -73,7 +73,7 @@ class ChannelController: UIViewController, UITableViewDelegate, UITableViewDataS
7373 if let _ = channel?.id { print("update")
7474 Model.updateChannel(with: channel!)
7575 } else { print("create")
76− Model.createChannel(with: channel!)
76+ //Model.createChannel(with: channel!)
7777 }
7878 return
7979 }
GDproject/Controller/ News and channels/ChannelListController.swift+1−1
@@ -30,7 +30,7 @@ class ChannelListController: UITableViewController {
3030 var displayingChannel: Model.Channels?
3131
3232 var toReload: Bool = false {
33− didSet{
33+ didSet {
3434 tableView.reloadData()
3535 }
3636 }
GDproject/Controller/ News and channels/ChannelViewController.swift+5−1
@@ -65,7 +65,11 @@ class ChannelViewController: UITableViewController, UpdatableName, UpdatableChan
6565 {
6666 Model.updateChannel(with: channel!)
6767 } else {
68− Model.createChannel(with: channel!)
68+ Model.createChannel(with: channel!) {
69+ [weak self] in
70+ self?.showAlertOn(result: $0)
71+ return
72+ }
6973 }
7074 return
7175 }
GDproject/Controller/ News and channels/FullPostController.swift+1−18
@@ -26,26 +26,9 @@ class FullPostController: UITableViewController {
2626 func setUpNavigationBar(){
2727 navigationItem.largeTitleDisplayMode = .never
2828 navigationItem.title = "Post"
29− navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(self.options))]
3029 }
3130
32− @objc func options(){
33− // drafts
34− // saved
35−
36− let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
37− let editAction = UIAlertAction(title: "Send via message", style: .default)
38− let shareAction = UIAlertAction(title: "Send via project", style: .default)
39− let settingsAction = UIAlertAction(title: "Copy link", style: .default)
40− let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
41−
42− optionMenu.addAction(editAction)
43− optionMenu.addAction(shareAction)
44− optionMenu.addAction(settingsAction)
45− optionMenu.addAction(cancelAction)
46−
47− self.present(optionMenu, animated: true, completion: nil)
48− }
31+
4932 // MARK: - Table view data source
5033
5134 override func numberOfSections(in tableView: UITableView) -> Int {
GDproject/Controller/ News and channels/NewPostViewController.swift+2−1
@@ -109,7 +109,8 @@ class NewPostViewController: UIViewController, UITextViewDelegate, TagsReceiver
109109 override func viewWillAppear(_ animated: Bool) {
110110 super.viewWillAppear(animated)
111111
112− navigationController?.navigationBar.prefersLargeTitles = false
112+ //navigationController?.navigationBar.prefersLargeTitles = false
113+ navigationItem.largeTitleDisplayMode = .never
113114 navigationItem.title = "New post"
114115 textView.text = NewPostViewController.draft
115116 // tagsField.addTags(NewPostViewController.hashTagsDraft)
GDproject/Controller/ News and channels/NewsController.swift+1
@@ -52,6 +52,7 @@ class NewsController: UIViewController, UISearchControllerDelegate, UpdateableWi
5252 let updater = TagsSuggestionController()
5353 updater.delegate = self
5454 searchController = UISearchController(searchResultsController: updater)
55+ navigationItem.largeTitleDisplayMode = .always
5556
5657 navigationController?.navigationBar.prefersLargeTitles = true
5758 navigationItem.title = "Loading ..."
GDproject/Controller/Coordinators/ProfileCoordinator.swift+15−13
@@ -36,23 +36,25 @@ class ProfileCoordinator: BaseCoordinator {
3636 }
3737 }
3838
39− profile.onSettings = { [weak self, weak storyboard] in
40− let vc = storyboard?.instantiateViewController(withIdentifier: "SettingsViewController") as! SettingsViewController
41− self?.navigationController?.pushViewController(vc, animated: true)
39+ profile.deleteAllSessions = {
40+ Model.deactivateAll() {
41+ [weak self] in
42+
43+ DataStorage.standard.setIsLoggedIn(value: false, with: 0)
44+ self?.didEndSession?()
45+ }
4246 }
4347
44− profile.onChannelsListToAddAPerson = { [weak self, weak storyboard] (user) in
45− let vc = storyboard?.instantiateViewController(withIdentifier: simplifiedChannelsList) as! SimplifiedChannelsList
46− vc.user = user
48+ profile.onSettings = { [weak self, weak storyboard, weak profile] in
49+
50+ let vc = storyboard?.instantiateViewController(withIdentifier: "RegisterTableViewController") as! RegisterTableViewController
51+ vc.delegate = profile
52+ vc.userActive = profile?.user
4753
48− let transition = CATransition()
49− transition.duration = 0.5
50− transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
51− transition.type = CATransitionType.moveIn
52− transition.subtype = CATransitionSubtype.fromTop
53− self?.navigationController?.view.layer.add(transition, forKey: nil)
54− self?.navigationController?.pushViewController(vc, animated: false)
54+ self?.navigationController?.pushViewController(vc, animated: true)
5555 }
56+
57+
5658 navigationController?.setViewControllers([profile], animated: false)
5759 }
5860}
GDproject/Controller/Log In/RegisterTableViewController.swift+52−11
@@ -11,9 +11,9 @@ import UIKit
1111class RegisterTableViewController: UITableViewController, ChosenFactulty
1212{
1313
14− func presentAlertInvalidData()
14+ func presentAlertInvalidData(message: String)
1515 {
16− let alert = UIAlertController(title: "Invalid data", message: "Some fields are missing. Add more information", preferredStyle: .alert)
16+ let alert = UIAlertController(title: "Invalid data", message: message, preferredStyle: .alert)
1717 alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
1818 self.present(alert, animated: true, completion: nil)
1919 }
@@ -23,12 +23,29 @@ class RegisterTableViewController: UITableViewController, ChosenFactulty
2323 tableView.reloadData()
2424 }
2525
26−
26+ weak var delegate: UpdateUser?
27+
2728 var onRegistration: (()->())?
2829
2930 var faculty: Model.Faculty?
3031 var user: Model.NewRegistration = Model.NewRegistration(email: DataStorage.standard.getEmail()!, firstName: nil, middleName: nil, lastName: nil, faculty: nil)
3132
33+ var userActive: Model.Users? {
34+ didSet {
35+ if let userA = userActive {
36+ user.firstName = userA.firstName
37+ user.middleName = userA.middleName
38+ user.lastName = userA.lastName
39+
40+ faculty = userA.faculty
41+ self.updateUserIfCan = true
42+ tableView.reloadData()
43+ }
44+ }
45+ }
46+
47+ var updateUserIfCan: Bool = false
48+
3249 override func viewDidLoad()
3350 {
3451 super.viewDidLoad()
@@ -38,22 +55,46 @@ class RegisterTableViewController: UITableViewController, ChosenFactulty
3855 navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(endRegistration))
3956 }
4057
58+
4159 @objc func endRegistration()
4260 {
61+ let fieldsMissing = "Some fields are missing. Add more information"
4362 updateUser()
44− guard let faculty = faculty else { presentAlertInvalidData(); return }
63+ guard let faculty = faculty else { presentAlertInvalidData(message: fieldsMissing); return }
4564
4665 user.faculty = faculty.url
4766
48− guard let _ = user.firstName else { presentAlertInvalidData(); return }
49− guard let _ = user.middleName else { presentAlertInvalidData(); return }
50− guard let _ = user.lastName else { presentAlertInvalidData(); return }
67+ guard let name = user.firstName else { presentAlertInvalidData(message: fieldsMissing); return }
68+ guard let middle = user.middleName else { presentAlertInvalidData(message: fieldsMissing); return }
69+ guard let last = user.lastName else { presentAlertInvalidData(message: fieldsMissing); return }
5170
52− Model.register(object: user)
53− { [weak self] in
54− self?.onRegistration?()
71+ if updateUserIfCan {
72+ guard let delegate = delegate else { return }
73+ guard var userA = userActive else { return }
74+
75+ // updating current
76+ userA.firstName = name
77+ userA.faculty = faculty
78+ userA.middleName = middle
79+ userA.lastName = last
80+
81+ Model.userUpdate(with: user) { [weak self] in
82+
83+ if $0 {
84+ delegate.updateUserObj(with: userA)
85+ self?.navigationController?.popViewController(animated: true)
86+ } else {
87+ self?.presentAlertInvalidData(message: "Something went wrong! Try again")
88+ }
89+
90+ }
91+ } else {
92+
93+ Model.register(object: user)
94+ { [weak self] in
95+ self?.onRegistration?()
96+ }
5597 }
56−
5798 }
5899 // MARK: - Table view data source
59100
GDproject/Controller/Messages/Dialog/DialogViewController.swift+2−1
@@ -248,7 +248,8 @@ class DialogViewController: UIViewController, UpdatableGroup, UITableViewDelegat
248248 return cellData.count
249249 }
250250
251− override func viewWillAppear(_ animated: Bool) {
251+ override func viewWillAppear(_ animated: Bool)
252+ {
252253 super.viewWillAppear(animated)
253254 tabBarController?.tabBar.isHidden = true
254255
GDproject/Controller/Messages/MessagesViewController.swift+2−2
@@ -70,10 +70,10 @@ class MessagesViewController: UITableViewController {
7070
7171 case .groupChat(let group):
7272 cell.textLabel?.text = group.group.name
73− cell.detailTextLabel?.text = group.lastMessage!.body.markdown
73+ cell.detailTextLabel?.text = group.lastMessage?.body.markdown
7474 case .userChat(let userChat):
7575 cell.textLabel?.text = "👤 \(users[userChat.user]!.fullName())"
76− cell.detailTextLabel?.text = userChat.lastMessage!.body.markdown
76+ cell.detailTextLabel?.text = userChat.lastMessage?.body.markdown
7777 }
7878
7979 return cell
GDproject/Controller/Profile/BasicInfoController.swift+16−11
@@ -16,17 +16,20 @@ struct CellData{
1616
1717class BasicInfoController: UIViewController, UITableViewDelegate, UITableViewDataSource {
1818
19− var dataSourse: [CellData] = [
20− CellData(opened: false, title: "Phone", sectionData: ["+7 901 733 01 79"]),
21− CellData(opened: false, title: "Mail", sectionData: ["vbogomazova@edu.hse.ru"]),
22− CellData(opened: false, title: "Research ID", sectionData: ["4567834336789456737"]),
23− CellData(opened: false, title: "Published", sectionData: ["Это будет очень длинное название книги 1, чтобы сделать проверку", "Книга 2", "Книга 3"]),
24− CellData(opened: false, title: "Courses", sectionData: ["Курс 1", "Курс 2"]),
25− CellData(opened: false, title: "Link", sectionData: ["https://wwww.hse.ru"])
26− ]
19+ var userInfo: Model.Users? {
20+ didSet {
21+ if let userInfo = userInfo {
22+ dataSourse = [CellData(opened: false, title: "Contacts", sectionData: [userInfo.email, userInfo.faculty.address]),
23+ CellData(opened: false, title: "Faculty", sectionData: [userInfo.faculty.campusName, userInfo.faculty.name, userInfo.faculty.address, userInfo.faculty.path]),
24+ CellData(opened: false, title: "Interests", sectionData: userInfo.faculty.tags)]
25+ }
26+ }
27+ }
28+
29+ var dataSourse: [CellData] = [ ]
2730
2831 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
29− if (dataSourse[section].opened){
32+ if (dataSourse[section].opened) {
3033 return dataSourse[section].sectionData.count + 1
3134 } else {
3235 return 1
@@ -45,8 +48,10 @@ class BasicInfoController: UIViewController, UITableViewDelegate, UITableViewDat
4548 cell.selectionStyle = .none
4649 return cell
4750 } else {
48− let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
49− cell.textLabel?.text = dataSourse[indexPath.section].sectionData[indexPath.row - 1]
51+ let cell = tableView.dequeueReusableCell(withIdentifier: infoCellId, for: indexPath) as! InfoCell
52+ cell.fill(title: dataSourse[indexPath.section].sectionData[indexPath.row - 1])
53+ cell.accessoryType = .none
54+ cell.selectionStyle = .none
5055 return cell
5156 }
5257 }
GDproject/Controller/Profile/InfoCell.swift+2−1
@@ -16,8 +16,9 @@ class InfoCell: UITableViewCell{
1616 label.font = UIFont.systemFont(ofSize: 16)
1717 label.sizeToFit()
1818 label.isScrollEnabled = false
19− label.isUserInteractionEnabled = false
19+ // label.isUserInteractionEnabled = false
2020 label.isEditable = false
21+ label.dataDetectorTypes = .all
2122 label.textColor = .black
2223 return label
2324 }()
GDproject/Controller/Profile/ProfileViewController.swift+63−21
@@ -9,8 +9,17 @@
99import UIKit
1010import TinyConstraints
1111
12−class ProfileViewController: UIViewController
12+protocol UpdateUser: class {
13+ func updateUserObj(with user: Model.Users)
14+}
15+
16+class ProfileViewController: UIViewController, UpdateUser
1317{
18+ func updateUserObj(with user: Model.Users)
19+ {
20+ self.user = user
21+ Model.Channels.fullPeopleDict[user.id] = user
22+ }
1423
1524 @IBOutlet weak var segmentedControl: UISegmentedControl!
1625
@@ -32,6 +41,8 @@ class ProfileViewController: UIViewController
3241
3342 var logOut: (()->())?
3443
44+ var deleteAllSessions: (()->())?
45+
3546 var onSettings: (()->())?
3647
3748 @IBAction func sendMessage(_ sender: UIButton)
@@ -46,8 +57,6 @@ class ProfileViewController: UIViewController
4657 }
4758 }
4859
49− var onChannelsListToAddAPerson: ((Model.Users)->())?
50−
5160 var protoDictionary: [String: UIImage] = ["135213": #imageLiteral(resourceName: "9"), "135288": #imageLiteral(resourceName: "5051"), "22723" : #imageLiteral(resourceName: "69"), "135083": #imageLiteral(resourceName: "42")]
5261
5362 func fill(with user: Model.Users)
@@ -106,6 +115,15 @@ class ProfileViewController: UIViewController
106115 posts.type = .NONE
107116 posts.currChannel = channel
108117
118+ posts.onFullPost = {
119+ [weak self] (type,post) in
120+
121+ let vc = self?.storyboard?.instantiateViewController(withIdentifier: fullPostControllerId) as! FullPostController
122+ vc.type = type
123+ vc.post = post
124+ self?.navigationController!.pushViewController(vc, animated: true)
125+ }
126+
109127 tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
110128
111129 tableView.register(PostViewCell.self, forCellReuseIdentifier: postCellId)
@@ -151,29 +169,52 @@ class ProfileViewController: UIViewController
151169
152170 let optionMenu = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
153171
154− let channelAction = UIAlertAction(title: "Add to a channel", style: .default){
155− [weak self] (_) in
156− self?.onChannelsListToAddAPerson?(self!.user!)
157− }
158−
159− let settingsAction = UIAlertAction(title: "Setting", style: .default)
160− { [weak self] (_) in
161− self?.onSettings?()
162− }
163−
172+
164173 let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
165174
166− let logoutAction = UIAlertAction(title: "Log out", style: .destructive)
167− { [weak self]
168− (_) in
169− self?.logOut?()
175+
176+ if idProfile == DataStorage.standard.getUserId() {
177+ let logoutAction = UIAlertAction(title: "Log out", style: .destructive)
178+ { [weak self]
179+ (_) in
180+ self?.logOut?()
181+ }
182+
183+ let deleetAllSessionsAction = UIAlertAction(title: "Delete all sessions", style: .destructive)
184+ { [weak self]
185+ (_) in
186+ self?.deleteAllSessions?()
187+ }
188+
189+ let settingsAction = UIAlertAction(title: "Edit profile", style: .default)
190+ { [weak self] (_) in
191+ self?.onSettings?()
192+ }
193+
194+ optionMenu.addAction(settingsAction)
195+ optionMenu.addAction(logoutAction)
196+ optionMenu.addAction(deleetAllSessionsAction)
197+ } else {
198+ let channelAction = UIAlertAction(title: "Add to a channel", style: .default)
199+ {
200+ [weak self] (_) in
201+
202+ let vc = self?.storyboard?.instantiateViewController(withIdentifier: simplifiedChannelsList) as! SimplifiedChannelsList
203+ vc.user = self?.user
204+
205+ let transition = CATransition()
206+ transition.duration = 0.5
207+ transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
208+ transition.type = CATransitionType.moveIn
209+ transition.subtype = CATransitionSubtype.fromTop
210+ self?.navigationController?.view.layer.add(transition, forKey: nil)
211+ self?.navigationController?.pushViewController(vc, animated: false)
212+ }
213+
214+ optionMenu.addAction(channelAction)
170215 }
171216
172− optionMenu.addAction(channelAction)
173− optionMenu.addAction(settingsAction)
174− optionMenu.addAction(logoutAction)
175217 optionMenu.addAction(cancelAction)
176−
177218 self.present(optionMenu, animated: true, completion: nil)
178219 }
179220
@@ -203,6 +244,7 @@ class ProfileViewController: UIViewController
203244 func changeToBasicInfo(){
204245 tableView.delegate = basicInfo
205246 tableView.dataSource = basicInfo
247+ basicInfo.userInfo = self.user
206248 tableView.reloadData()
207249 }
208250}
GDproject/Extentions.swift+30
@@ -77,3 +77,33 @@ extension String {
7777 return timeStamp
7878 }
7979}
80+
81+extension UIViewController {
82+ func showAlertOn(result: ResultR) {
83+
84+ let message: String
85+
86+ switch result {
87+ case .impossibleContent:
88+ message = "Impossible content"
89+ case .exceededContent:
90+ message = "The content exceeded"
91+ case .longContent:
92+ message = "The content is too long"
93+ case .badAccess:
94+ message = "Try reloading the page again"
95+ case .alreadyRegistered:
96+ message = "User is already registered"
97+ case .tooMuchToAdd:
98+ message = "Limit of channels exceeded"
99+ case .success, .success1:
100+ return
101+ default:
102+ message = "Something went wrong"
103+ }
104+
105+ let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert)
106+ alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
107+ self.present(alert, animated: true, completion: nil)
108+ }
109+}
GDproject/Simple model/Model.swift+63−9
@@ -10,6 +10,22 @@ import Foundation
1010import UIKit
1111import Alamofire
1212
13+enum ResultR: Int {
14+ case internalServerError = 500
15+ case exceededContent = 470
16+ case longContent = 471
17+ case incorrectContent = 472
18+ case impossibleContent = 473
19+ case invalidTocken = 498
20+ case alreadyRegistered = 409
21+ case invalidCode = 403
22+ case badAccess = 400
23+ case tooMuchToAdd = 406
24+ case notFound = 404
25+ case success1 = 204
26+ case success = 200
27+}
28+
1329class Model{
1430
1531 static let invalidTocken = 498
@@ -17,7 +33,7 @@ class Model{
1733 static var hashTagTree: CompletionTree?
1834
1935 private static var isValidTocken: ((Int)->())? = { responce in
20−
36+ print(responce)
2137 if responce == invalidTocken {
2238
2339 DataStorage.standard.setIsLoggedIn(value: false, with: 0)
@@ -33,6 +49,7 @@ class Model{
3349 static let decoder = JSONDecoder()
3450
3551 static let authMeURL = URL(string: "\(baseUrl)/authentication/me")!
52+ static let deactivateURL = URL(string: "\(baseUrl)/deactivateAll")!
3653 static let registerMeURL = URL(string: "\(baseUrl)/authentication/register")!
3754 static let authVerifyURL = URL(string: "\(baseUrl)/authentication/verify")!
3855 static let authenticationURL = URL(string:"\(baseUrl)/authentication/login")!
@@ -42,6 +59,7 @@ class Model{
4259 static let postsPublishURL = URL(string:"\(baseUrl)/posts/publish")!
4360 static let usersURL = URL(string:"\(baseUrl)/users")!
4461 static let usersAllURL = URL(string:"\(baseUrl)/users/all")!
62+ static let usersUpdateURL = URL(string:"\(baseUrl)/users/update")!
4563 static let channelsGetURL = URL(string: "\(baseUrl)/channels/get")!
4664 static let channelsUpdateURL = URL(string: "\(baseUrl)/channels/update")!
4765 static let channelsListURL = URL(string: "\(baseUrl)/channels")!
@@ -251,15 +269,13 @@ class Model{
251269 }
252270
253271 if code == 204 {
254− let fields = responce.response?.allHeaderFields as? [String :String]
255272
273+ let fields = responce.response?.allHeaderFields as? [String :String]
256274 let cookies = HTTPCookie.cookies(withResponseHeaderFields: fields!, for: responce.response!.url!)
257−
258275 HTTPCookieStorage.shared.setCookie(cookies[0])
259276
260277 completion()
261278 }
262−
263279 }
264280 }
265281
@@ -470,7 +486,7 @@ class Model{
470486
471487 static func getUsers(for ids: [Int], completion: @escaping (([Int:Users])->())){
472488 let json = "\(Set(ids))"
473− print(json)
489+
474490 var request = URLRequest(url: usersURL)
475491
476492 request.httpMethod = "POST"
@@ -534,7 +550,7 @@ class Model{
534550 }
535551
536552
537− static func createChannel(with channel: Channels) {
553+ static func createChannel(with channel: Channels, completion: @escaping ((ResultR)->())) {
538554
539555 var request = URLRequest(url: channelsCreateURL)
540556 request.httpMethod = "POST"
@@ -545,9 +561,13 @@ class Model{
545561 (response) in
546562
547563 isValidTocken?(response.response?.statusCode ?? 498)
548− if let code = response.response?.statusCode, code == 498 {
564+
565+ if let code = response.response?.statusCode, let result = ResultR(rawValue: code) {
566+ completion(result)
549567 return
550568 }
569+
570+ completion(ResultR.internalServerError)
551571 }
552572
553573 }
@@ -709,8 +729,6 @@ class Model{
709729 guard let json = response.data else { return }
710730
711731 guard let newQueery = try? decoder.decode(QueryPosts<Posts>.self, from: json) else { return }
712−
713− print("\(anonymousChannel) \(newQueery)")
714732 completion((newQueery.users, newQueery.response))
715733 }
716734 }
@@ -1081,4 +1099,40 @@ class Model{
10811099 completion(faculties)
10821100 }
10831101 }
1102+
1103+ static func userUpdate(with newUser: NewRegistration, completion: @escaping ((Bool)->())) {
1104+ var request = URLRequest(url: usersUpdateURL)
1105+ request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
1106+ request.httpMethod = "POST"
1107+ request.httpBody = try? JSONEncoder().encode(newUser)
1108+
1109+ AF.request(request).response { (response) in
1110+ isValidTocken?(response.response?.statusCode ?? 498)
1111+
1112+ if let code = response.response?.statusCode, code == 498 {
1113+ return
1114+ }
1115+
1116+ if let code = response.response?.statusCode, code != 204{
1117+ completion (false)
1118+ } else {
1119+ completion(true)
1120+ }
1121+ }
1122+ }
1123+
1124+ static func deactivateAll(completion: @escaping (()->())){
1125+ var request = URLRequest(url: deactivateURL)
1126+ request.httpMethod = "DELETE"
1127+
1128+ AF.request(request).response { (responce) in
1129+ isValidTocken?(responce.response?.statusCode ?? 498)
1130+
1131+ if let code = responce.response?.statusCode, code == 498 {
1132+ return
1133+ }
1134+
1135+ completion()
1136+ }
1137+ }
10841138}