30 |
33 |
34 |
35 |
36 |
37 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/Resources/Views/srsq/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
私人社区官网
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
46 |
47 |
48 |

49 |
50 |
51 |
发现一个 有趣的app
52 |
此时此刻
53 |
私人社区在这里诞生,社区,圈子应有尽有集成聊天功能,无需添加好友,随意畅聊
54 |
57 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
84 |
85 |
86 |
87 |

88 |
89 |
90 |
聊天系统
91 |
集成融云RCIM即时通讯聊天服务
92 |
93 |
94 |

95 |
96 |
97 |
安全系统
98 |
采用移动端最流行的第三方登陆,保证用户账号安全
99 |
100 |
101 |

102 |
103 |
104 |
动态发布
105 |
随时随地,发布动态,和好友分享你身边的新鲜事~
106 |
107 |
108 |

109 |
110 |
111 |
网络系统
112 |
采用科技最前沿的swift服务器,云端托管在heroku,24小时为你服务
113 |
114 |
115 |

116 |
117 |
118 |
用户系统
119 |
你可以无需添加好友就可以和你心仪的人聊天,随意畅聊
120 |
121 |
122 |
123 |
124 |
125 |

126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |

137 |
138 |
139 |
小菜iOS
140 |
私人社区app创始人,同时也是一名iOS开发者,热衷于分享技术,专注移动开发领域
141 |
142 | 
143 | 
144 | 
145 | 
146 | 
147 |
148 |
149 |
150 |
151 |
152 |
主要技能,objective-c,swift,html,vapor后台server,微信小程序,目前正在研究leaf语言
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
私人社区iOS app界面截图
162 |
163 | 目前1.0版本新增功能:
164 | 1.优化即时聊天IM
165 | 2.压缩安装包大小
166 | 3.app极限省流量
167 | 4.支持上传相册
168 | 5.无限制内容分享
169 | 6.动态发布支持连接,点击可调转
170 | 7.社区列表流畅度提升
171 |
172 |
173 |
174 |
175 |

176 |
177 |
178 |

179 |
180 |
181 |

182 |
183 |
184 |

185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
app 功能演示
196 |
网站部分功能暂不可用,社长正在紧张建设中,尽请期待
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
联系我们
209 |
邮箱:625225273@qq.com
210 |
微博:http://weibo.com/u/5100479224
211 |
地址:上海市普陀区曹杨路329号 上海私人社区科技有限公司
212 |
213 | 
214 |
215 |
Copyright © 2015.Company srsq All rights reserved.
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Sources/App/main.swift:
--------------------------------------------------------------------------------
1 | import Vapor
2 | import VaporPostgreSQL
3 | import HTTP
4 | import Auth
5 | import TurnstileCrypto
6 | import Foundation
7 |
8 | // MARK: - 0.初始化
9 |
10 | let drop = Droplet()
11 | let auth = AuthMiddleware(user:SQFriend.self)
12 | drop.middleware.append(auth)
13 | do {
14 | try drop.addProvider(VaporPostgreSQL.Provider.self)
15 | } catch {
16 | print("Error adding provider: \(error)")
17 | }
18 | drop.preparations = [SQFriend.self,SQRcToken.self,SQAllUser.self,SQProfile.self,SQActive.self,SQBanner.self,SQPic.self,SQPerson.self,SQAnimal.self]
19 |
20 | drop.get { req in
21 | return try drop.view.make("welcome", [
22 | "message": drop.localization[req.lang, "welcome", "title"] ])
23 | }
24 |
25 | // MARK: - 1.朋友 第三方登陆 API
26 | drop.group("friends") { friends in
27 |
28 | // MARK: - 1.1 如果该用户已经登陆过,可以从cookie中获取用户信息
29 | let protect = ProtectMiddleware(error:
30 | Abort.custom(status: .forbidden, message: "Not authorized.")
31 | )
32 | friends.group(protect) { secure in
33 | secure.get("secure") { req in
34 |
35 | let haveFriend = try req.user()
36 | let rc = try SQRcToken.query().filter("account",haveFriend.account).first()
37 | return try JSON(node: [
38 | "result" : "0",
39 | "token":rc!.token,
40 | "rctoken":rc!.rctoken,
41 | "data": haveFriend.makeJSON()
42 | ])
43 | }
44 | }
45 |
46 | friends.post("friendLogin") { req in
47 |
48 | guard let openid = req.data["openid"]?.string else {
49 | throw Abort.badRequest
50 | }
51 | let rc = try SQRcToken.query().filter("openid",openid).first()
52 | if rc != nil { // 用户直接登陆
53 | let haveFriend = try SQFriend.query().filter("account",rc!.account).first()
54 | // let creds = Identifier(id: (haveFriend?.id)!) // 缓存用户登录信息,下次直接从cookie获取
55 | // try req.auth.login(creds)
56 |
57 | return try JSON(node: [
58 | "result" : "0",
59 | "token":rc!.token,
60 | "rctoken":rc!.rctoken,
61 | "data": haveFriend!.makeJSON()
62 | ])
63 | } else {
64 | // 用户不存在,创建用户
65 | return try JSON(node: [
66 | "result" : "4040",
67 | ])
68 | }
69 | }
70 | // 保存融云token 接口
71 | friends.post("rctoken") { req in
72 | guard let username = req.data["username"]?.string else {
73 | throw Abort.badRequest
74 | }
75 | guard let sex = req.data["sex"]?.string else {
76 | throw Abort.badRequest
77 | }
78 | guard let headimgurl = req.data["headimgurl"]?.string else {
79 | throw Abort.badRequest
80 | }
81 | guard let openid = req.data["openid"]?.string else {
82 | throw Abort.badRequest
83 | }
84 | guard let deviceno = req.data["deviceno"]?.string else {
85 | throw Abort.badRequest
86 | }
87 | guard let way = req.data["way"]?.string else {
88 | throw Abort.badRequest
89 | }
90 | guard let rctoken = req.data["rctoken"]?.string else {
91 | throw Abort.badRequest
92 | }
93 | guard let rcuserid = req.data["rcuserid"]?.string else {
94 | throw Abort.badRequest
95 | }
96 |
97 | // =================================== 条件限制 =================================== //
98 | let haveRc = try SQRcToken.query().filter("openid",openid).first()
99 | if haveRc != nil { // 已经存在
100 | return try JSON(node: [
101 | "result" : "4000",
102 | ])
103 | }
104 | let allF = try SQFriend.query().filter("deviceno",deviceno).all()
105 | if allF.count >= 10 {
106 | return try JSON(node: [
107 | "result" : "4000",
108 | ])
109 | }
110 | // =================================== 条件限制 =================================== //
111 |
112 | // 生成账号
113 | var acc_date = Date().timeIntervalSince1970*100
114 | let acc_tempTimeStr = String(format: "%.f", acc_date)
115 | let account_RandStr = URandom().secureToken
116 | let account = way + acc_tempTimeStr + account_RandStr
117 |
118 | // 生成token
119 | var date = Date().timeIntervalSince1970*100
120 | let tempTimeStr = String(format: "%.f", date)
121 | let randStr = URandom().secureToken
122 | let token = tempTimeStr + randStr
123 |
124 | var friend = SQFriend(username: username,sex:sex, headimgurl: headimgurl,rcuserid:rcuserid, deviceno: deviceno, way: way, account: account, pwd:"", aboutme:"", zannum:0, photos:"",tags:"", activities:"")
125 | try friend.save()
126 |
127 | var rc = SQRcToken(account:account, token:token, openid:openid, rctoken: rctoken)
128 | try rc.save()
129 |
130 | return try JSON(node: [
131 | "result" : "0",
132 | "token":rc.token,
133 | "rctoken":rc.rctoken,
134 | "data": friend.makeJSON()
135 | ])
136 | }
137 | // 所有用户赞 接口
138 | friends.post("zan") { req in
139 | guard let rcuserid = req.data["rcuserid"]?.string else {
140 | throw Abort.badRequest
141 | }
142 | var friend = try SQFriend.query().filter("rcuserid", rcuserid).first()
143 | friend?.zannum += 1
144 | try friend?.save()
145 | return try JSON(node: [
146 | "result" : "0",
147 | ])
148 | }
149 | }
150 | // MARK: - 2.个人资料
151 | drop.group("user") { user in
152 |
153 | // 查询个人中心资料
154 | user.post("profile") { req in
155 | guard let account = req.data["account"]?.string else {
156 | throw Abort.badRequest
157 | }
158 | var friend = try SQFriend.query().filter("account", account).first()
159 | if friend != nil {
160 | return try JSON(node: [
161 | "result" : "0",
162 | "data":JSON(node: friend!.makeJSON())
163 | ])
164 | } else {
165 | return try JSON(node: [
166 | "result" : "1",
167 | ])
168 | }
169 | }
170 |
171 | // 更新个人中心资料
172 | user.post("updateNick") { req in
173 | guard let account = req.data["account"]?.string else {
174 | throw Abort.badRequest
175 | }
176 | guard let token = req.data["token"]?.string else {
177 | throw Abort.badRequest
178 | }
179 | guard let username = req.data["username"]?.string else {
180 | throw Abort.badRequest
181 | }
182 |
183 | var friend = try SQFriend.query().filter("account", account).first()
184 | if friend != nil {
185 | var rcModel = try SQRcToken.query().filter("token", token).first()
186 | if rcModel != nil {
187 | if (rcModel?.token.equals(any: token))! {
188 | friend?.username = username
189 | try friend?.save()
190 | return try JSON(node: [
191 | "result" : "0",
192 | ])
193 | } else {
194 | return try JSON(node: [
195 | "result" : "1",
196 | ])
197 | }
198 | } else {
199 | return try JSON(node: [
200 | "result" : "1",
201 | ])
202 | }
203 | } else {
204 | return try JSON(node: [
205 | "result" : "1",
206 | ])
207 | }
208 | }
209 |
210 | user.post("updateAboutMe") { req in
211 | guard let account = req.data["account"]?.string else {
212 | throw Abort.badRequest
213 | }
214 | guard let token = req.data["token"]?.string else {
215 | throw Abort.badRequest
216 | }
217 | guard let aboutme = req.data["aboutme"]?.string else {
218 | throw Abort.badRequest
219 | }
220 |
221 | var friend = try SQFriend.query().filter("account", account).first()
222 | if friend != nil {
223 | var rcModel = try SQRcToken.query().filter("token", token).first()
224 | if rcModel != nil {
225 | if (rcModel?.token.equals(any: token))! {
226 | friend?.aboutme = aboutme
227 | try friend?.save()
228 | return try JSON(node: [
229 | "result" : "0",
230 | ])
231 | } else {
232 | return try JSON(node: [
233 | "result" : "1",
234 | ])
235 | }
236 | } else {
237 | return try JSON(node: [
238 | "result" : "1",
239 | ])
240 | }
241 | } else {
242 | return try JSON(node: [
243 | "result" : "1",
244 | ])
245 | }
246 | }
247 | user.post("updateTags") { req in
248 | guard let account = req.data["account"]?.string else {
249 | throw Abort.badRequest
250 | }
251 | guard let token = req.data["token"]?.string else {
252 | throw Abort.badRequest
253 | }
254 | guard let tags = req.data["tags"]?.string else {
255 | throw Abort.badRequest
256 | }
257 |
258 | var friend = try SQFriend.query().filter("account", account).first()
259 | if friend != nil {
260 | var rcModel = try SQRcToken.query().filter("token", token).first()
261 | if rcModel != nil {
262 | if (rcModel?.token.equals(any: token))! {
263 | friend?.tags = tags
264 | try friend?.save()
265 | return try JSON(node: [
266 | "result" : "0",
267 | ])
268 | } else {
269 | return try JSON(node: [
270 | "result" : "1",
271 | ])
272 | }
273 | } else {
274 | return try JSON(node: [
275 | "result" : "1",
276 | ])
277 | }
278 | } else {
279 | return try JSON(node: [
280 | "result" : "1",
281 | ])
282 | }
283 | }
284 | user.post("updatePhotos") { req in
285 | guard let account = req.data["account"]?.string else {
286 | throw Abort.badRequest
287 | }
288 | guard let token = req.data["token"]?.string else {
289 | throw Abort.badRequest
290 | }
291 | guard let photos = req.data["photos"]?.string else {
292 | throw Abort.badRequest
293 | }
294 |
295 | var friend = try SQFriend.query().filter("account", account).first()
296 | if friend != nil {
297 | var rcModel = try SQRcToken.query().filter("token", token).first()
298 | if rcModel != nil {
299 | if (rcModel?.token.equals(any: token))! {
300 | friend?.photos = photos
301 | try friend?.save()
302 | return try JSON(node: [
303 | "result" : "0",
304 | "photos" : photos
305 | ])
306 | } else {
307 | return try JSON(node: [
308 | "result" : "1",
309 | ])
310 | }
311 | } else {
312 | return try JSON(node: [
313 | "result" : "1",
314 | ])
315 | }
316 | } else {
317 | return try JSON(node: [
318 | "result" : "1",
319 | ])
320 | }
321 | }
322 | user.post("updateHeaderImage") { req in
323 | guard let account = req.data["account"]?.string else {
324 | throw Abort.badRequest
325 | }
326 | guard let token = req.data["token"]?.string else {
327 | throw Abort.badRequest
328 | }
329 | guard let headimgurl = req.data["headimgurl"]?.string else {
330 | throw Abort.badRequest
331 | }
332 | var friend = try SQFriend.query().filter("account", account).first()
333 | if friend != nil {
334 | var rcModel = try SQRcToken.query().filter("token", token).first()
335 | if rcModel != nil {
336 | if (rcModel?.token.equals(any: token))! {
337 | friend?.headimgurl = headimgurl
338 | try friend?.save()
339 | return try JSON(node: [
340 | "result" : "0",
341 | "headimgurl" : headimgurl
342 | ])
343 | } else {
344 | return try JSON(node: [
345 | "result" : "1",
346 | ])
347 | }
348 | } else {
349 | return try JSON(node: [
350 | "result" : "1",
351 | ])
352 | }
353 | } else {
354 | return try JSON(node: [
355 | "result" : "1",
356 | ])
357 | }
358 | }
359 | }
360 | // MARK: - 3.广场 API
361 | drop.group("allUsers") { allUsers in
362 | allUsers.get("allFriends") { req in
363 | let friends = try SQFriend.all()
364 | let sqpic = try SQPic.all().first
365 | return try JSON(node: [
366 | "result" : "0",
367 | "data" : JSON(node: friends.makeJSON()),
368 | "pic" : sqpic?.pic,
369 | "color" : "FC6E5E"
370 | ])
371 | }
372 | }
373 |
374 | // MARK: - 4.banner API
375 | drop.group("sqbanner") { sqbanner in
376 | sqbanner.get("banner") { req in
377 | return try JSON(node: SQBanner.all().makeJSON())
378 | }
379 | // 新增banner条
380 | sqbanner.post("addbanner") { req in
381 | guard let imgurl = req.data["imgurl"]?.string else {
382 | throw Abort.badRequest
383 | }
384 | guard let neturl = req.data["neturl"]?.string else {
385 | throw Abort.badRequest
386 | }
387 | guard let btype = req.data["btype"]?.int else {
388 | throw Abort.badRequest
389 | }
390 | guard let squserid = req.data["squserid"]?.string else {
391 | throw Abort.badRequest
392 | }
393 | guard let bannertext = req.data["bannertext"]?.string else {
394 | throw Abort.badRequest
395 | }
396 |
397 | var banner = SQBanner(imgurl: imgurl, neturl: neturl, btype: btype, squserid: squserid, bannertext: bannertext)
398 | try banner.save()
399 | return try JSON(node: [
400 | "result" : "0"
401 | ])
402 | }
403 |
404 | sqbanner.post("sqpic") { rep in
405 | guard let pic = rep.data["pic"]?.string else {
406 | throw Abort.badRequest
407 | }
408 | var sqpic = SQPic(pic: pic)
409 | try sqpic.save()
410 | return try JSON(node: [
411 | "result" : "0"
412 | ])
413 | }
414 | }
415 |
416 | // MARK: - 5.动态 API
417 | drop.group("sqacitves") { sqacitves in
418 |
419 | sqacitves.post("act") { req in
420 | guard let page = req.data["page"]?.int else {
421 | throw Abort.badRequest
422 | }
423 | return try JSON(node: [
424 | "result" : "0",
425 | "data" : JSON(node: SQActive.all().makeJSON()),
426 | "haveMore":"Y"
427 | ])
428 | }
429 | sqacitves.post("release") { req in
430 |
431 | guard let username = req.data["username"]?.string else {
432 | throw Abort.badRequest
433 | }
434 | guard let sex = req.data["sex"]?.string else {
435 | throw Abort.badRequest
436 | }
437 | guard let headimgurl = req.data["headimgurl"]?.string else {
438 | throw Abort.badRequest
439 | }
440 | guard let account = req.data["account"]?.string else {
441 | throw Abort.badRequest
442 | }
443 | guard let token = req.data["token"]?.string else {
444 | throw Abort.badRequest
445 | }
446 | guard let actcontent = req.data["actcontent"]?.string else {
447 | throw Abort.badRequest
448 | }
449 | guard let zancount = req.data["zancount"]?.int else {
450 | throw Abort.badRequest
451 | }
452 | guard let commoncount = req.data["commoncount"]?.int else {
453 | throw Abort.badRequest
454 | }
455 | guard let photostr = req.data["photostr"]?.string else {
456 | throw Abort.badRequest
457 | }
458 | guard let sqlocal = req.data["sqlocal"]?.string else {
459 | throw Abort.badRequest
460 | }
461 | guard let acttime = req.data["acttime"]?.string else {
462 | throw Abort.badRequest
463 | }
464 | guard let rcuserid = req.data["rcuserid"]?.string else {
465 | throw Abort.badRequest
466 | }
467 | guard let width = req.data["width"]?.double else {
468 | throw Abort.badRequest
469 | }
470 | guard let height = req.data["height"]?.double else {
471 | throw Abort.badRequest
472 | }
473 |
474 | var rcToken = try SQRcToken.query().filter("account", account).first()
475 | if (rcToken?.token.equals(any: token))! {
476 | var act = SQActive(username: username, sex: sex, headimgurl: headimgurl, account: account, actcontent: actcontent, photostr: photostr, zancount: zancount, commoncount: commoncount, sqlocal: sqlocal, acttime: acttime, rcuserid: rcuserid, width: width, height: height)
477 | try act.save()
478 |
479 | var fri = try SQFriend.query().filter("account", account).first()
480 | if (fri?.activities.equals(any: ""))! {
481 | fri?.activities = acttime
482 | } else {
483 | fri?.activities = (fri?.activities)! + "," + acttime
484 | }
485 | try fri?.save()
486 | return try JSON(node: [
487 | "result" : "0",
488 | "data" : JSON(node: act.makeJSON())
489 | ])
490 | } else {
491 | return try JSON(node: [
492 | "result" : "1",
493 | ])
494 | }
495 | }
496 | sqacitves.post("zan") { req in
497 | guard let id = req.data["id"]?.string else {
498 | throw Abort.badRequest
499 | }
500 | var act = try SQActive.query().filter("id", id).first()
501 | act?.zancount += 1
502 | try act?.save()
503 | return try JSON(node: [
504 | "result" : "0",
505 | ])
506 | }
507 | }
508 | // MARK: - 6.Apple 专用
509 | drop.group("apple") { apple in
510 | apple.post("login") { req in
511 | guard let account = req.data["account"]?.string else {
512 | throw Abort.badRequest
513 | }
514 | guard let pwd = req.data["pwd"]?.string else {
515 | throw Abort.badRequest
516 | }
517 | if account.equals(any: "123456789") && pwd.equals(any: "123654") {
518 | let haveFriend = try SQFriend.query().filter("id", 1).first()
519 | let rc = try SQRcToken.query().filter("account", (haveFriend?.account)!).first()
520 | return try JSON(node: [
521 | "result" : "0",
522 | "token":rc!.token,
523 | "rctoken":rc!.rctoken,
524 | "data": haveFriend!.makeJSON()
525 | ])
526 | }
527 | let f = try SQFriend.query().filter("name",.greaterThan, 21).all()
528 |
529 | let haveFriend = try SQFriend.query().filter("pwd", "123").first()
530 | let rc = try SQRcToken.query().filter("account", (haveFriend?.account)!).first()
531 | return try JSON(node: [
532 | "result" : "1"
533 | ])
534 | }
535 | }
536 |
537 | // MARK: - 7.网页接口
538 | drop.get("/srsq") { request in
539 | let dict = request.json
540 | return try drop.view.make("srsq/index.html")
541 | }
542 | drop.get("/home") { request in
543 |
544 | let id = request.data["id"]?.int
545 | if id != nil {
546 | return try JSON(node: [
547 | "result" : "1",
548 | "data":JSON(node: SQActive.find(id!)?.makeJSON())
549 | ])
550 | }
551 | return try drop.view.make("home/welcome.html")
552 | }
553 | drop.get("shareData") { request in
554 | guard let id = request.data["id"]?.string else {
555 | throw Abort.badRequest
556 | }
557 | var act = try SQActive.find(id)
558 | if act != nil {
559 | return try JSON(node: [
560 | "result" : "0",
561 | "data":JSON(node: act?.makeJSON())
562 | ])
563 | } else {
564 | return try JSON(node: [
565 | "result" : "1",
566 | ])
567 | }
568 | }
569 | drop.get("profileShare") { request in
570 | guard let account = request.data["id"]?.string else {
571 | throw Abort.badRequest
572 | }
573 | var act = try SQFriend.query().filter("account", account).first();
574 | if act != nil {
575 | return try JSON(node: [
576 | "result" : "0",
577 | "data":JSON(node: act?.makeJSON())
578 | ])
579 | } else {
580 | return try JSON(node: [
581 | "result" : "1",
582 | ])
583 | }
584 | }
585 | drop.get("/share") { request in
586 | return try drop.view.make("share/index.html")
587 | }
588 | // MARK: - 8.1 版本更新
589 | drop.post("version") { request in
590 |
591 | guard let version = request.data["version"]?.string else {
592 | throw Abort.badRequest
593 | }
594 | if version.equals(any: "1.5.0") {
595 | return try JSON(node: [
596 | "result": "0",
597 | "msg": "0"
598 | ])
599 | } else {
600 | return try JSON(node: [
601 | "result": "1",
602 | "msg": "发现新版:1.3.0,更新内容:\n1.优化即时聊天IM\n2.压缩安装包大小\n3.极限省流量\n4.支持上传相册\n5.无限制内容分享\n6.动态发布支持连接,点击可调转\n7.社区列表流畅度提升\n8.支持https\n9.消息推送、自定义推送\n10.安全的cookie自动登录策略"
603 | ])
604 | }
605 | }
606 | // MARK: - 8.2 安全策略
607 | drop.post("cysafee") { request in
608 | guard let v = request.data["v"]?.string else {
609 | throw Abort.badRequest
610 | }
611 | guard let c = request.data["c"]?.int else {
612 | throw Abort.badRequest
613 | }
614 | return try JSON(node: [
615 | "l": "111",
616 | "s": "1",
617 | "c": "0",
618 | ])
619 | }
620 |
621 | // MARK: - 9.1 演示 API
622 | drop.get("leaf") { request in
623 | return try drop.view.make("template", [
624 | "greeting": "Hello, world!"
625 | ])
626 | }
627 | drop.get("session") { request in
628 | let json = try JSON(node: [
629 | "session.data": "\(request.session().data["name"])",
630 | "request.cookies": "\(request.cookies)",
631 | "instructions": "Refresh to see cookie and session get set."
632 | ])
633 | var response = try Response(status: .ok, json: json)
634 | try request.session().data["name"] = "Vapor"
635 | response.cookies["test"] = "123"
636 |
637 | return response
638 | }
639 | drop.get("data", Int.self) { request, int in
640 | return try JSON(node: [
641 | "int": int,
642 | "name": request.data["name"]?.string ?? "no name"
643 | ])
644 | }
645 | drop.get("json") { request in
646 | return try JSON(node: [
647 | "number": 123,
648 | "string": "test",
649 | "array": try JSON(node: [
650 | 0, 1, 2, 3
651 | ]),
652 | "dict": try JSON(node: [
653 | "name": "Vapor",
654 | "lang": "Swift"
655 | ])
656 | ])
657 | }
658 |
659 | // MARK: - 10 待调查
660 | // 1.cookie 时长
661 |
662 | drop.resource("posts", PostController())
663 | drop.run()
664 |
--------------------------------------------------------------------------------
/HelloVapor.xcodeproj/xcshareddata/xcschemes/HelloVapor.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
29 |
35 |
36 |
37 |
43 |
49 |
50 |
51 |
57 |
63 |
64 |
65 |
71 |
77 |
78 |
79 |
85 |
91 |
92 |
93 |
99 |
105 |
106 |
107 |
113 |
119 |
120 |
121 |
127 |
133 |
134 |
135 |
141 |
147 |
148 |
149 |
155 |
161 |
162 |
163 |
169 |
175 |
176 |
177 |
183 |
189 |
190 |
191 |
197 |
203 |
204 |
205 |
211 |
217 |
218 |
219 |
225 |
231 |
232 |
233 |
239 |
245 |
246 |
247 |
253 |
259 |
260 |
261 |
267 |
273 |
274 |
275 |
281 |
287 |
288 |
289 |
295 |
301 |
302 |
303 |
309 |
315 |
316 |
317 |
323 |
329 |
330 |
331 |
337 |
343 |
344 |
345 |
351 |
357 |
358 |
359 |
365 |
371 |
372 |
373 |
379 |
385 |
386 |
387 |
393 |
399 |
400 |
401 |
407 |
413 |
414 |
415 |
421 |
427 |
428 |
429 |
435 |
441 |
442 |
443 |
449 |
455 |
456 |
457 |
463 |
469 |
470 |
471 |
477 |
483 |
484 |
485 |
491 |
497 |
498 |
499 |
505 |
511 |
512 |
513 |
519 |
525 |
526 |
527 |
533 |
539 |
540 |
541 |
547 |
553 |
554 |
555 |
561 |
567 |
568 |
569 |
575 |
581 |
582 |
583 |
589 |
595 |
596 |
597 |
603 |
609 |
610 |
611 |
617 |
623 |
624 |
625 |
626 |
627 |
632 |
633 |
634 |
635 |
636 |
637 |
647 |
648 |
654 |
655 |
656 |
657 |
658 |
659 |
665 |
666 |
668 |
669 |
672 |
673 |
674 |
--------------------------------------------------------------------------------