| 130 |
ashish |
1 |
'''
|
|
|
2 |
Created on 28-Apr-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from shop2020.model.v1.user.impl import Dataservice
|
|
|
7 |
from shop2020.utils.Utils import log_entry, to_py_date, to_java_date
|
| 1273 |
varun.gupt |
8 |
from shop2020.model.v1.user.impl.Dataservice import User, UserCommunication, IPMap,\
|
| 1845 |
vikas |
9 |
Address, SocialHandle, UserState, InternalInfo, SocialService, Affiliate, Tracker, TrackLog,\
|
|
|
10 |
MasterAffiliate
|
| 130 |
ashish |
11 |
from shop2020.thriftpy.model.v1.user.ttypes import UserContextException,\
|
| 557 |
chandransh |
12 |
AuthenticationException, AccountStatus, Sex
|
| 581 |
rajveer |
13 |
from shop2020.clients.HelperClient import HelperClient
|
| 130 |
ashish |
14 |
from elixir import session
|
| 873 |
rajveer |
15 |
import datetime, random, string
|
| 581 |
rajveer |
16 |
from shop2020.thriftpy.utils.ttypes import Mail
|
| 130 |
ashish |
17 |
|
| 1249 |
chandransh |
18 |
def initialize(dbname='user'):
|
| 130 |
ashish |
19 |
log_entry("initialize@DataAccessor", "Initializing data service")
|
| 1249 |
chandransh |
20 |
Dataservice.initialize(dbname)
|
| 557 |
chandransh |
21 |
|
|
|
22 |
def create_anonymous_user(jsession_id, cart):
|
| 576 |
chandransh |
23 |
user=User.get_by(jsession_id=jsession_id)
|
|
|
24 |
if not user is None:
|
|
|
25 |
return user
|
| 557 |
chandransh |
26 |
user = User()
|
|
|
27 |
anonymous_str = "anonymous"
|
| 576 |
chandransh |
28 |
user.email = jsession_id + "@anonymous.com"
|
| 557 |
chandransh |
29 |
user.password = anonymous_str
|
|
|
30 |
user.name = anonymous_str
|
|
|
31 |
user.communication_email = jsession_id + "@anonymous.com"
|
|
|
32 |
user.jsession_id = jsession_id
|
|
|
33 |
user.is_anonymous = True
|
|
|
34 |
user.sex = Sex.WONT_SAY
|
|
|
35 |
user.active_cart_id = cart.id
|
|
|
36 |
#initialize userState
|
|
|
37 |
user_state = UserState()
|
|
|
38 |
user_state.is_email_verified = False
|
|
|
39 |
user_state.is_sms_verified = False
|
|
|
40 |
user_state.account_status = AccountStatus.ACTIVE
|
|
|
41 |
user_state.ip_list = []
|
|
|
42 |
user_state.active_since = datetime.datetime.now()
|
|
|
43 |
user_state.user = user
|
| 1607 |
vikas |
44 |
session.commit();
|
| 557 |
chandransh |
45 |
|
|
|
46 |
cart.user_id = user.id
|
|
|
47 |
session.commit()
|
| 130 |
ashish |
48 |
|
| 557 |
chandransh |
49 |
return user
|
|
|
50 |
|
|
|
51 |
def get_user_by_id(user_id):
|
|
|
52 |
return User.get_by(id=user_id)
|
|
|
53 |
|
| 1491 |
vikas |
54 |
def get_user_by_email(email):
|
|
|
55 |
return User.get_by(email=email)
|
|
|
56 |
|
| 557 |
chandransh |
57 |
def create_user(user_to_add, cart):
|
|
|
58 |
if user_to_add.userId:
|
| 130 |
ashish |
59 |
raise UserContextException(109, "id is set, user cannot be created")
|
| 557 |
chandransh |
60 |
user = User()
|
|
|
61 |
user.email = user_to_add.email
|
|
|
62 |
user.password = user_to_add.password
|
|
|
63 |
user.name = user_to_add.name
|
|
|
64 |
user.communication_email = user_to_add.communicationEmail
|
|
|
65 |
user.jsession_id = user_to_add.jsessionId
|
|
|
66 |
user.is_anonymous = False
|
|
|
67 |
user.sex = user_to_add.sex
|
| 567 |
rajveer |
68 |
user.date_of_birth = user_to_add.dateOfBirth
|
| 557 |
chandransh |
69 |
user.active_cart_id = cart.id
|
| 567 |
rajveer |
70 |
user.mobile_number = user_to_add.mobileNumber
|
| 513 |
rajveer |
71 |
|
| 130 |
ashish |
72 |
#initialize userState
|
| 557 |
chandransh |
73 |
user_state = UserState()
|
| 130 |
ashish |
74 |
user_state.is_email_verified = False
|
|
|
75 |
user_state.is_sms_verified = False
|
|
|
76 |
user_state.account_status = AccountStatus.ACTIVE
|
| 132 |
ashish |
77 |
user_state.ip_list = []
|
| 130 |
ashish |
78 |
user_state.active_since = datetime.datetime.now()
|
| 557 |
chandransh |
79 |
user_state.user = user
|
| 1607 |
vikas |
80 |
session.commit();
|
| 130 |
ashish |
81 |
|
| 557 |
chandransh |
82 |
#Now create the user phones. Mostly, this should only be a mobile number
|
|
|
83 |
|
|
|
84 |
cart.user_id = user.id
|
| 130 |
ashish |
85 |
session.commit()
|
| 404 |
rajveer |
86 |
|
| 557 |
chandransh |
87 |
return user
|
| 130 |
ashish |
88 |
|
|
|
89 |
#===============================================================================
|
|
|
90 |
# Need to provide the update apis here for relevant fields in PrimaryInfo.
|
|
|
91 |
#===============================================================================
|
| 557 |
chandransh |
92 |
def update_user(user_to_update):
|
| 594 |
rajveer |
93 |
if not user_to_update.userId:
|
| 415 |
ashish |
94 |
raise UserContextException(110, "user does not exist")
|
| 594 |
rajveer |
95 |
user = get_user_by_id(user_to_update.userId)
|
|
|
96 |
user.email = user_to_update.email
|
|
|
97 |
user.password = user_to_update.password
|
|
|
98 |
user.name = user_to_update.name
|
|
|
99 |
user.communication_email = user_to_update.communicationEmail
|
|
|
100 |
user.jsession_id = user_to_update.jsessionId
|
|
|
101 |
user.is_anonymous = user_to_update.isAnonymous
|
|
|
102 |
user.sex = user_to_update.sex
|
|
|
103 |
user.date_of_birth = user_to_update.dateOfBirth
|
|
|
104 |
user.active_cart_id = user_to_update.activeCartId
|
|
|
105 |
user.mobile_number = user_to_update.mobileNumber
|
| 415 |
ashish |
106 |
session.commit()
|
| 594 |
rajveer |
107 |
return user
|
| 415 |
ashish |
108 |
|
| 557 |
chandransh |
109 |
def delete_user(user_id):
|
|
|
110 |
user = get_user_by_id(user_id)
|
| 130 |
ashish |
111 |
|
|
|
112 |
if not user:
|
|
|
113 |
raise_user_exception(user_id)
|
| 557 |
chandransh |
114 |
|
|
|
115 |
user.state.account_status = AccountStatus.DELETED
|
|
|
116 |
session.commit()
|
|
|
117 |
return True
|
| 130 |
ashish |
118 |
|
| 557 |
chandransh |
119 |
def get_user_state(user_id):
|
| 766 |
rajveer |
120 |
userstate = UserState.get_by(user_id=user_id)
|
|
|
121 |
return userstate
|
| 130 |
ashish |
122 |
|
| 557 |
chandransh |
123 |
def get_internal_info(user_id):
|
| 766 |
rajveer |
124 |
info = InternalInfo.get_by(user_id=user_id)
|
|
|
125 |
return info
|
| 130 |
ashish |
126 |
|
| 557 |
chandransh |
127 |
def authenticate_user(user_handle, password):
|
|
|
128 |
user = User.get_by(email=user_handle)
|
| 130 |
ashish |
129 |
if not user:
|
| 557 |
chandransh |
130 |
raise AuthenticationException("This email address is not registered.", 102)
|
| 130 |
ashish |
131 |
|
| 557 |
chandransh |
132 |
if user.password == get_db_password(password):
|
|
|
133 |
return user
|
| 130 |
ashish |
134 |
else:
|
|
|
135 |
raise AuthenticationException("Wrong username or password", 102)
|
|
|
136 |
|
|
|
137 |
def user_exists(email):
|
| 413 |
rajveer |
138 |
try:
|
| 557 |
chandransh |
139 |
user = User.get_by(email=email)
|
|
|
140 |
if user:
|
|
|
141 |
return True
|
|
|
142 |
else:
|
|
|
143 |
return False
|
| 413 |
rajveer |
144 |
except:
|
| 130 |
ashish |
145 |
return False
|
|
|
146 |
|
| 567 |
rajveer |
147 |
def add_address_for_user(address, user_id, set_default):
|
| 557 |
chandransh |
148 |
user = get_user_by_id(user_id)
|
| 766 |
rajveer |
149 |
|
| 130 |
ashish |
150 |
if not user:
|
|
|
151 |
raise_user_exception(user_id)
|
|
|
152 |
if not address:
|
|
|
153 |
raise UserContextException(103,"Address cannot be null")
|
|
|
154 |
|
|
|
155 |
address_to_add = Address()
|
|
|
156 |
address_to_add.line_1 = address.line1
|
|
|
157 |
address_to_add.line_2 = address.line2
|
|
|
158 |
address_to_add.landmark = address.landmark
|
|
|
159 |
address_to_add.city = address.city
|
|
|
160 |
address_to_add.country = address.country
|
|
|
161 |
address_to_add.state = address.state
|
|
|
162 |
address_to_add.pin = address.pin
|
|
|
163 |
address_to_add.type = address.type
|
| 414 |
ashish |
164 |
address_to_add.name = address.name
|
|
|
165 |
address_to_add.phone = address.phone
|
| 130 |
ashish |
166 |
address_to_add.added_on = to_py_date(address.addedOn)
|
|
|
167 |
address_to_add.enabled = True
|
| 557 |
chandransh |
168 |
address_to_add.user = user
|
| 130 |
ashish |
169 |
session.commit()
|
| 509 |
rajveer |
170 |
|
| 557 |
chandransh |
171 |
if set_default is True:
|
|
|
172 |
user.default_address_id = address_to_add.id
|
| 567 |
rajveer |
173 |
#set default address if nothing is default
|
|
|
174 |
if user.default_address_id is None:
|
|
|
175 |
user.default_address_id = address_to_add.id
|
|
|
176 |
|
| 557 |
chandransh |
177 |
session.commit()
|
| 513 |
rajveer |
178 |
|
| 567 |
rajveer |
179 |
return address_to_add.id
|
| 513 |
rajveer |
180 |
|
| 130 |
ashish |
181 |
def remove_address_for_user(user_id, address_id):
|
|
|
182 |
address = get_address(address_id)
|
|
|
183 |
|
|
|
184 |
if not address:
|
| 557 |
chandransh |
185 |
raise UserContextException(103, "Address not found")
|
|
|
186 |
if address.user.id != user_id:
|
|
|
187 |
raise UserContextException(104, "This address belongs to some other user")
|
| 130 |
ashish |
188 |
|
|
|
189 |
address.enabled = False
|
|
|
190 |
session.commit()
|
|
|
191 |
return True
|
|
|
192 |
|
|
|
193 |
def set_user_as_logged_in(user_id, time_stamp):
|
| 557 |
chandransh |
194 |
user_state = UserState.get_by(user_id=user_id)
|
|
|
195 |
#user = get_user_by_id(user_id)
|
| 130 |
ashish |
196 |
|
| 557 |
chandransh |
197 |
if not user_state:
|
|
|
198 |
raise_user_exception(user_id)
|
| 130 |
ashish |
199 |
|
|
|
200 |
if not time_stamp:
|
| 557 |
chandransh |
201 |
user_state.last_login = datetime.datetime.now()
|
|
|
202 |
else:
|
|
|
203 |
user_state.last_login = to_py_date(time_stamp)
|
| 130 |
ashish |
204 |
session.commit()
|
|
|
205 |
return True
|
|
|
206 |
|
| 557 |
chandransh |
207 |
def set_user_as_logged_out(user_id, time_stamp):
|
|
|
208 |
user_state = UserState.get_by(user_id=user_id)
|
| 130 |
ashish |
209 |
|
| 557 |
chandransh |
210 |
if not user_state:
|
| 130 |
ashish |
211 |
raise_user_exception(user_id)
|
|
|
212 |
|
|
|
213 |
if not time_stamp:
|
| 557 |
chandransh |
214 |
user_state.last_logout = datetime.datetime.now()
|
|
|
215 |
else:
|
|
|
216 |
user_state.last_logout = to_py_date(time_stamp)
|
| 130 |
ashish |
217 |
session.commit()
|
|
|
218 |
return True
|
|
|
219 |
|
| 557 |
chandransh |
220 |
def set_default_address(user_id, address_id):
|
|
|
221 |
user = get_user_by_id(user_id)
|
|
|
222 |
address = Address.get_by(id=address_id)
|
|
|
223 |
if not user:
|
|
|
224 |
raise_user_exception(user_id)
|
|
|
225 |
if not address:
|
|
|
226 |
raise UserContextException(103, "Address not found")
|
|
|
227 |
if address.user.id != user.id:
|
|
|
228 |
raise UserContextException(104, "This address belongs to some other user")
|
|
|
229 |
|
|
|
230 |
user.default_address_id = address_id
|
|
|
231 |
session.commit()
|
|
|
232 |
|
| 594 |
rajveer |
233 |
def update_password(user_id, old_password, new_password):
|
| 557 |
chandransh |
234 |
user = get_user_by_id(user_id)
|
| 130 |
ashish |
235 |
|
|
|
236 |
if not user:
|
|
|
237 |
raise_user_exception(user_id)
|
|
|
238 |
|
| 594 |
rajveer |
239 |
if user.password != old_password:
|
|
|
240 |
return False
|
|
|
241 |
|
|
|
242 |
if check_for_valid_password(new_password):
|
|
|
243 |
user.password = get_db_password(new_password)
|
| 130 |
ashish |
244 |
session.commit()
|
|
|
245 |
return True
|
|
|
246 |
else:
|
|
|
247 |
return False
|
| 1273 |
varun.gupt |
248 |
|
|
|
249 |
|
|
|
250 |
def create_user_communication(user_id, email, communication_type, order_id, awb, product, subject, message):
|
|
|
251 |
|
|
|
252 |
user_communication = UserCommunication()
|
|
|
253 |
user_communication.user_id = user_id
|
|
|
254 |
user_communication.communication_type = communication_type
|
| 1743 |
varun.gupt |
255 |
|
|
|
256 |
if order_id > 0:
|
|
|
257 |
user_communication.order_id = order_id
|
| 1273 |
varun.gupt |
258 |
user_communication.airwaybill_no = awb
|
|
|
259 |
user_communication.reply_to = email
|
|
|
260 |
user_communication.product_name = product
|
|
|
261 |
user_communication.subject = subject
|
|
|
262 |
user_communication.message = message
|
| 1301 |
varun.gupt |
263 |
user_communication.communication_timestamp = datetime.datetime.now()
|
| 1273 |
varun.gupt |
264 |
session.commit()
|
| 130 |
ashish |
265 |
|
| 1583 |
varun.gupt |
266 |
def get_user_communication_by_id(user_communication_id):
|
|
|
267 |
return UserCommunication.get_by(id = user_communication_id)
|
|
|
268 |
|
|
|
269 |
def get_user_communication_by_user(user_communication_user_id):
|
| 1607 |
vikas |
270 |
return UserCommunication.query.filter_by(user_id = user_communication_user_id).order_by(-UserCommunication.id).all()
|
| 1583 |
varun.gupt |
271 |
|
|
|
272 |
def get_all_user_communications():
|
| 1863 |
vikas |
273 |
return UserCommunication.query.order_by(-UserCommunication.id).all()
|
| 1583 |
varun.gupt |
274 |
|
| 1859 |
vikas |
275 |
def create_master_affiliate(name, added_on):
|
| 1845 |
vikas |
276 |
master_affiliate = MasterAffiliate()
|
|
|
277 |
master_affiliate.name = name
|
| 1859 |
vikas |
278 |
master_affiliate.added_on = to_py_date(added_on)
|
| 1845 |
vikas |
279 |
session.commit()
|
|
|
280 |
return master_affiliate
|
|
|
281 |
|
| 1899 |
vikas |
282 |
def get_all_master_affiliates():
|
|
|
283 |
return MasterAffiliate.query.all()
|
|
|
284 |
|
| 1845 |
vikas |
285 |
def get_master_affiliate_by_id(id):
|
|
|
286 |
return MasterAffiliate.get_by(id = id)
|
|
|
287 |
|
|
|
288 |
def get_master_affiliate_by_name(name):
|
|
|
289 |
return MasterAffiliate.get_by(name = name)
|
|
|
290 |
|
| 1859 |
vikas |
291 |
def create_affiliate(name, url, master_affiliate_id, added_on):
|
| 1845 |
vikas |
292 |
affiliate = Affiliate()
|
|
|
293 |
affiliate.name = name
|
|
|
294 |
if url is not None:
|
|
|
295 |
affiliate.url = url
|
|
|
296 |
affiliate.master_affiliate_id = master_affiliate_id
|
| 1859 |
vikas |
297 |
affiliate.added_on = to_py_date(added_on)
|
| 1845 |
vikas |
298 |
session.commit()
|
|
|
299 |
return affiliate
|
|
|
300 |
|
|
|
301 |
def get_affiliate_by_id(id):
|
|
|
302 |
return Affiliate.get_by(id = id)
|
|
|
303 |
|
|
|
304 |
def get_affiliate_by_name(name):
|
|
|
305 |
return Affiliate.get_by(name = name)
|
|
|
306 |
|
|
|
307 |
def get_affiliates_by_master_affiliate(master_affiliate_id):
|
|
|
308 |
return MasterAffiliate.get_by(id = master_affiliate_id).affiliates
|
|
|
309 |
|
|
|
310 |
def get_tracker_by_id(id):
|
|
|
311 |
return Tracker.get_by(id = id)
|
|
|
312 |
|
| 1996 |
vikas |
313 |
def add_track_log(affiliate_id, user_id, event, url, data, added_on):
|
| 1845 |
vikas |
314 |
track_log = TrackLog()
|
| 1996 |
vikas |
315 |
track_log.affiliate_id = affiliate_id
|
| 1845 |
vikas |
316 |
if user_id:
|
|
|
317 |
track_log.user_id = user_id
|
|
|
318 |
track_log.event = event
|
|
|
319 |
if url:
|
|
|
320 |
track_log.url = url
|
|
|
321 |
if data:
|
| 1859 |
vikas |
322 |
track_log.data = data
|
|
|
323 |
track_log.added_on = to_py_date(added_on)
|
| 1845 |
vikas |
324 |
session.commit()
|
|
|
325 |
return track_log.id
|
|
|
326 |
|
|
|
327 |
def get_track_log_by_id(id):
|
|
|
328 |
return TrackLog.get_by(id = id)
|
|
|
329 |
|
| 1996 |
vikas |
330 |
def get_track_logs_by_affiliate(affiliate_id):
|
|
|
331 |
return Affiliate.get_by(id = affiliate_id).tracklogs
|
| 1845 |
vikas |
332 |
|
|
|
333 |
def get_track_logs_by_user(user_id):
|
|
|
334 |
return TrackLog.query.filter(TrackLog.user_id == user_id).all()
|
|
|
335 |
|
| 1996 |
vikas |
336 |
def get_track_logs(affiliate_id, user_id, event, url):
|
| 1845 |
vikas |
337 |
query = TrackLog.query
|
|
|
338 |
|
| 1996 |
vikas |
339 |
if affiliate_id:
|
|
|
340 |
query = query.filter(TrackLog.affiliate_id == affiliate_id)
|
|
|
341 |
if user_id:
|
|
|
342 |
query = query.filter(TrackLog.user_id == user_id)
|
| 1845 |
vikas |
343 |
if event:
|
|
|
344 |
query = query.filter(TrackLog.event == event)
|
|
|
345 |
if url:
|
|
|
346 |
query = query.filter(TrackLog.url == url)
|
|
|
347 |
return query.all()
|
|
|
348 |
|
|
|
349 |
|
| 557 |
chandransh |
350 |
def get_address(address_id):
|
|
|
351 |
address = Address.get_by(id=address_id)
|
|
|
352 |
return address
|
|
|
353 |
|
|
|
354 |
def get_social_service(service_id):
|
|
|
355 |
service = SocialService.get_by(service_id)
|
|
|
356 |
return service
|
|
|
357 |
|
|
|
358 |
def add_ip_address_for_user(ip_address, time_stamp, user_id):
|
|
|
359 |
user = get_user_by_id(user_id)
|
| 130 |
ashish |
360 |
if not user:
|
|
|
361 |
raise_user_exception(user_id)
|
| 557 |
chandransh |
362 |
#user exists create an IP address object
|
|
|
363 |
ip_address = IPMap()
|
|
|
364 |
ip_address.ip = ip_address
|
|
|
365 |
ip_address.timestamp = to_py_date(time_stamp)
|
|
|
366 |
ip_address.user_state = user.state
|
| 130 |
ashish |
367 |
session.commit()
|
|
|
368 |
return True
|
|
|
369 |
|
|
|
370 |
def get_social_service_by_name(service_name):
|
|
|
371 |
service = SocialService.get_by(name=service_name)
|
|
|
372 |
|
|
|
373 |
if not service:
|
|
|
374 |
raise UserContextException(106, "No such social service exists")
|
|
|
375 |
return service
|
|
|
376 |
|
|
|
377 |
def add_social_handle(user_id, social_service, handle):
|
| 557 |
chandransh |
378 |
user = get_user_by_id(user_id)
|
| 130 |
ashish |
379 |
|
|
|
380 |
if not user:
|
|
|
381 |
raise_user_exception(user_id)
|
|
|
382 |
|
|
|
383 |
service = get_social_service_by_name(social_service)
|
|
|
384 |
|
|
|
385 |
#get if use already has this service.
|
| 557 |
chandransh |
386 |
social_handle = SocialHandle.filter(service=service).filter(user=user).one()
|
| 130 |
ashish |
387 |
if not social_handle:
|
|
|
388 |
#create a new handle
|
|
|
389 |
social_handle = SocialHandle()
|
|
|
390 |
social_handle.service = service
|
| 557 |
chandransh |
391 |
social_handle.user = user
|
| 130 |
ashish |
392 |
social_handle.handle = handle
|
|
|
393 |
else:
|
|
|
394 |
social_handle.handle = handle
|
| 557 |
chandransh |
395 |
session.commit()
|
| 130 |
ashish |
396 |
return True
|
| 557 |
chandransh |
397 |
|
| 884 |
rajveer |
398 |
|
|
|
399 |
def forgot_password(email, password):
|
|
|
400 |
try:
|
|
|
401 |
user = User.get_by(email=email)
|
|
|
402 |
if user:
|
|
|
403 |
user.password = password
|
| 900 |
rajveer |
404 |
session.commit()
|
| 884 |
rajveer |
405 |
return True
|
|
|
406 |
else:
|
|
|
407 |
return False
|
|
|
408 |
except:
|
|
|
409 |
return False
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
'''
|
| 581 |
rajveer |
413 |
def forgot_password(email):
|
|
|
414 |
try:
|
|
|
415 |
user = User.get_by(email=email)
|
|
|
416 |
if user:
|
| 873 |
rajveer |
417 |
new_password = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(8))
|
| 581 |
rajveer |
418 |
mail = Mail()
|
|
|
419 |
mail.to = []
|
|
|
420 |
mail.to.append(email)
|
|
|
421 |
mail.sender = ""
|
|
|
422 |
mail.password = ""
|
|
|
423 |
mail.data = "Your new password is " + user.password
|
|
|
424 |
helper_client = HelperClient()
|
|
|
425 |
helper_client.__start__()
|
|
|
426 |
client = helper_client.get_client()
|
|
|
427 |
client.sendMail(mail);
|
| 873 |
rajveer |
428 |
|
| 581 |
rajveer |
429 |
return True
|
|
|
430 |
else:
|
|
|
431 |
return False
|
|
|
432 |
except:
|
|
|
433 |
return False
|
| 884 |
rajveer |
434 |
'''
|
| 581 |
rajveer |
435 |
|
| 594 |
rajveer |
436 |
def get_all_addresses_for_user(userId):
|
|
|
437 |
query = Address.query.filter(Address.user.has(id = userId))
|
|
|
438 |
query = query.filter(Address.enabled == True)
|
|
|
439 |
return query.all()
|
| 581 |
rajveer |
440 |
|
| 785 |
rajveer |
441 |
def get_default_address_id(userId):
|
| 594 |
rajveer |
442 |
user = get_user_by_id(userId);
|
| 840 |
chandransh |
443 |
if user.default_address_id is None:
|
|
|
444 |
return 0
|
| 594 |
rajveer |
445 |
return user.default_address_id
|
| 581 |
rajveer |
446 |
|
| 785 |
rajveer |
447 |
def get_default_pincode(user_id):
|
|
|
448 |
user = get_user_by_id(user_id)
|
|
|
449 |
if not user:
|
|
|
450 |
raise_user_exception(user_id)
|
|
|
451 |
default_address_id = user.default_address_id
|
|
|
452 |
if default_address_id:
|
|
|
453 |
address = Address.get_by(id=default_address_id)
|
|
|
454 |
default_pincode = address.pin
|
|
|
455 |
else:
|
|
|
456 |
default_pincode = '110001'
|
|
|
457 |
return default_pincode
|
| 1596 |
ankur.sing |
458 |
|
|
|
459 |
def get_user_count(user_type):
|
|
|
460 |
if user_type is None:
|
|
|
461 |
return User.query.count()
|
|
|
462 |
else:
|
|
|
463 |
return User.query.filter_by(is_anonymous = user_type).count()
|
| 785 |
rajveer |
464 |
|
| 1891 |
ankur.sing |
465 |
def get_users(user_type, start_date, end_date):
|
|
|
466 |
query = session.query(User).join(UserState)
|
|
|
467 |
if start_date != -1:
|
|
|
468 |
query = query.filter(UserState.active_since >= to_py_date(start_date))
|
|
|
469 |
if end_date != -1:
|
|
|
470 |
query = query.filter(UserState.active_since <= to_py_date(end_date))
|
|
|
471 |
if user_type is not None:
|
|
|
472 |
query = query.filter(User.is_anonymous == user_type)
|
|
|
473 |
return query.all()
|
| 1673 |
ankur.sing |
474 |
|
| 130 |
ashish |
475 |
#=============================================================================
|
|
|
476 |
# Helper functions
|
|
|
477 |
#=============================================================================
|
|
|
478 |
|
|
|
479 |
'''
|
|
|
480 |
This function returns the password as stored in the db
|
|
|
481 |
'''
|
|
|
482 |
def get_db_password(password):
|
|
|
483 |
return password
|
|
|
484 |
|
|
|
485 |
def check_for_valid_password(password):
|
|
|
486 |
if not password:
|
|
|
487 |
raise UserContextException(105,"password cannot be null")
|
|
|
488 |
return True
|
|
|
489 |
#------------------------------------------------------------------------------
|
|
|
490 |
|
|
|
491 |
#===============================================================================
|
|
|
492 |
# raises the UserContextException
|
|
|
493 |
#===============================================================================
|
|
|
494 |
def raise_user_exception(user_id):
|
| 766 |
rajveer |
495 |
raise UserContextException(101, "no such user in system %d" %(user_id))
|
|
|
496 |
|
|
|
497 |
def close_session():
|
|
|
498 |
if session.is_active:
|
|
|
499 |
print "session is active. closing it."
|
|
|
500 |
session.close()
|