[web2py] Re: admin panle with uwsgi

2013-05-20 Thread yashar
yes but what is the password? how could i set password?

On Monday, May 20, 2013 3:10:23 PM UTC+4:30, Niphlod wrote:
>
> the appadmin is accessible if you previously logged in into the /admin/ 
> application (usually https://yourhost/admin/default/site page).
> Did you do that step ?
>
> Il giorno lunedì 20 maggio 2013 12:31:31 UTC+2, yashar ha scritto:
>>
>> yes , if i want to run it from uwsgi.
>>
>> On Monday, May 20, 2013 2:44:53 PM UTC+4:30, Niphlod wrote:
>>>
>>> so the problem is that you can't reach the 
>>> https://yourhost/appname/appadmin page ?
>>>
>>>
>>> Il giorno lunedì 20 maggio 2013 11:58:48 UTC+2, yashar ha scritto:
>>>>
>>>> thanks for the fast reply, yes the problem is speed over ssh connection 
>>>> but let me ask like this, is this possible to run appmin panel with uwsgi? 
>>>> i know i have to use ssh for connecting at last. when i run it with uwsgi 
>>>> it replys : no password was set for appadmin
>>>>
>>>> On Monday, May 20, 2013 2:06:28 PM UTC+4:30, Niphlod wrote:
>>>>>
>>>>> honestly I don't get what you want.
>>>>> When you use ssh to connect to the host you have the same exact speed 
>>>>> than connecting through http to that host.
>>>>> Accessing the admin app with or without the ssh tunnelling can't 
>>>>> generate problems on the speed side: the required bandwith is roughly the 
>>>>> same.
>>>>> So the question is: what do you want to do exactly?
>>>>>
>>>>> Il giorno lunedì 20 maggio 2013 10:51:00 UTC+2, yashar ha scritto:
>>>>>>
>>>>>> using ssh for connecting to admin panel is slow, if it was possible 
>>>>>> to use something like connecting to application folder for retrieving 
>>>>>> models/controller/view.. files and using local admin panel could boost 
>>>>>> the 
>>>>>> speed.
>>>>>>
>>>>>> my question:
>>>>>>
>>>>>> is this possible to use uwsgi and pass password to it?
>>>>>>
>>>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: admin panle with uwsgi

2013-05-20 Thread yashar
yes , if i want to run it from uwsgi.

On Monday, May 20, 2013 2:44:53 PM UTC+4:30, Niphlod wrote:
>
> so the problem is that you can't reach the 
> https://yourhost/appname/appadmin page ?
>
>
> Il giorno lunedì 20 maggio 2013 11:58:48 UTC+2, yashar ha scritto:
>>
>> thanks for the fast reply, yes the problem is speed over ssh connection 
>> but let me ask like this, is this possible to run appmin panel with uwsgi? 
>> i know i have to use ssh for connecting at last. when i run it with uwsgi 
>> it replys : no password was set for appadmin
>>
>> On Monday, May 20, 2013 2:06:28 PM UTC+4:30, Niphlod wrote:
>>>
>>> honestly I don't get what you want.
>>> When you use ssh to connect to the host you have the same exact speed 
>>> than connecting through http to that host.
>>> Accessing the admin app with or without the ssh tunnelling can't 
>>> generate problems on the speed side: the required bandwith is roughly the 
>>> same.
>>> So the question is: what do you want to do exactly?
>>>
>>> Il giorno lunedì 20 maggio 2013 10:51:00 UTC+2, yashar ha scritto:
>>>>
>>>> using ssh for connecting to admin panel is slow, if it was possible to 
>>>> use something like connecting to application folder for retrieving 
>>>> models/controller/view.. files and using local admin panel could boost the 
>>>> speed.
>>>>
>>>> my question:
>>>>
>>>> is this possible to use uwsgi and pass password to it?
>>>>
>>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: admin panle with uwsgi

2013-05-20 Thread yashar
thanks for the fast reply, yes the problem is speed over ssh connection but 
let me ask like this, is this possible to run appmin panel with uwsgi? i 
know i have to use ssh for connecting al last.

On Monday, May 20, 2013 2:06:28 PM UTC+4:30, Niphlod wrote:
>
> honestly I don't get what you want.
> When you use ssh to connect to the host you have the same exact speed than 
> connecting through http to that host.
> Accessing the admin app with or without the ssh tunnelling can't generate 
> problems on the speed side: the required bandwith is roughly the same.
> So the question is: what do you want to do exactly?
>
> Il giorno lunedì 20 maggio 2013 10:51:00 UTC+2, yashar ha scritto:
>>
>> using ssh for connecting to admin panel is slow, if it was possible to 
>> use something like connecting to application folder for retrieving 
>> models/controller/view.. files and using local admin panel could boost the 
>> speed.
>>
>> my question:
>>
>> is this possible to use uwsgi and pass password to it?
>>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] admin panle with uwsgi

2013-05-20 Thread yashar
using ssh for connecting to admin panel is slow, if it was possible to use 
something like connecting to application folder for retrieving 
models/controller/view.. files and using local admin panel could boost the 
speed.

my question:

is this possible to use uwsgi and pass password to it?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] change dal connection string user

2013-05-19 Thread yashar
hi, 

i want to change connection string user from postgres to another_user but 
it said relation auth_user already exist, i thought that i set fake_migrate 
= True to solve it but i'm not sure.

any idea to how to solve it?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: sqlform custom fails to hide errors

2013-04-25 Thread yashar
thanks, what is the difference between hideerror in sqlform and 
form.process? i noticed errors hide only if i use hideerror in sqlform not 
in form.process

On Thursday, April 25, 2013 5:16:27 PM UTC+4:30, Anthony wrote:
>
> During validation, each input gets its own reference to form.errors, so if 
> you simply replace form.errors, each input will still refer to the original 
> form.errors. So, instead of replacing form.errors, you have to alter it:
>
> form.errors.clear()
>
> Anyway, this shouldn't be necessary, because you can just do:
>
> form.process(..., hideerror=True)
>
> Anthony
>
> On Thursday, April 25, 2013 3:02:46 AM UTC-4, yashar wrote:
>>
>> i set form.errors = dict() at the end of controller but i still get 
>> errors, is this a bug or i'm doing a wrong way?
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] sqlform custom fails to hide errors

2013-04-25 Thread yashar
i set form.errors = dict() at the end of controller but i still get errors, 
is this a bug or i'm doing a wrong way?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] auth ajax - how about this way?

2013-04-01 Thread yashar

is this true that SQLFORMs redirected to _next value when SQLFORM is 
accepted? so i did this:

def lost_password():
from gluon.serializers import json
try:
form = auth.retrieve_password()
except: ### i assume that form redirected only if email send to user 
return json(dict(form=DIV('Please check your email, an email sent 
to you ',INPUT(_type='button',_value='Close',_class='btn btn-primary', 
_onclick="$('#Modallogin').modal('hide');"
return json(dict(form=form))

i checked that and it works, any idea?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: signed url

2013-03-29 Thread yashar
thank you, now i understand it.

On Wednesday, March 27, 2013 5:21:24 PM UTC+4:30, Anthony wrote:
>
> The user signature is a hash of the URL, and by default this includes the 
> query string. However, your code uses Javascript to append the query string 
> after web2py creates the URL and its signature, so once the request is 
> made, the user signature no longer matches the hash of the full URL 
> including the query string (note, even when working properly, the 
> user_signature would not be the same as the HMAC key -- the HMAC key is 
> simply used as the key to create the hash of the URL).
>
> If you must append the query string on the client side, then you can 
> create the user signature excluding the query string via:
>
> URL(..., user_signature=True, hash_vars=False)
>
> In this case, though, you will not be able to verify the query string via 
> the digital signature (i.e., a user could manually change the query string 
> part of the URL and still have the request verified). See 
> http://web2py.com/books/default/chapter/29/04#Digitally-signed-urls for 
> more details.
>
> Anthony
>
> On Wednesday, March 27, 2013 6:55:21 AM UTC-4, yashar wrote:
>>
>>
>> here is the link :
>> 
>>   window.location.href = 
>> '{{=URL('CS','close_inqueries',user_signature=True)}}'  + '&' + data;
>> 
>>
>> and here is the controler:
>> def close_inqueries():
>> print request.vars
>> print '-'*20
>> print session
>>
>> and here is the result:
>> > 'Sea-24': 'on'}>
>> 
>> > 'is_mobile': False, 'dist': {'name': 'Ubuntu'}, 'browser': {'version': 
>> '19.0', 'name': 'Firefox'}}, '_auth_next': None, 'flash': None, 
>> 'user_type': 'CS', 'auth': > 'bbdd4f5d-2cfa-4ee8-a7b4-c08a3b7874ee', 'remember': False, 'last_visit': 
>> datetime.datetime(2013, 3, 27, 11, 48, 35, 442411), 'expiration': 3600, 
>> 'user': > '', 'email': 'a...@naghi.com', 'reset_password_key': '', 
>> 'registration_key': '', 'id': 4}>, 'user_groups': {3: 'user_4'}}>, 
>> 'nickname': 'ali', '_session_hash': 'c55603687a5f7482dda9b0d85a7a78e1', 
>> '_formkey[login]': 'c8974fec-1b1d-4c47-9f5c-dbd4c765542c'}>
>>
>> as you see _signature and hmac_key have different values and i think this 
>> is the reason i get non authorized alert when i add 
>> @auth.requires_signature() to controller.
>>
>> what is the correct way to do this?
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] signed url

2013-03-27 Thread yashar

here is the link :

  window.location.href = 
'{{=URL('CS','close_inqueries',user_signature=True)}}'  + '&' + data;


and here is the controler:
def close_inqueries():
print request.vars
print '-'*20
print session

and here is the result:


, 'user_groups': {3: 'user_4'}}>, 'nickname': 'ali', 
'_session_hash': 'c55603687a5f7482dda9b0d85a7a78e1', '_formkey[login]': 
'c8974fec-1b1d-4c47-9f5c-dbd4c765542c'}>

as you see _signature and hmac_key have different values and i think this 
is the reason i get non authorized alert when i add 
@auth.requires_signature() to controller.

what is the correct way to do this?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] signed url

2013-03-27 Thread yashar
here is the link :

  window.location.href = 
'{{=URL('CS','close_inqueries',user_signature=True)}}'  + '&' + data;


and here is the controler:
def close_inqueries():
print request.vars
print '-'*20
print session

and here is the result:


, 'user_groups': {3: 'user_4'}}>, 'nickname': 'ali', 
'_session_hash': 'c55603687a5f7482dda9b0d85a7a78e1', '_formkey[login]': 
'c8974fec-1b1d-4c47-9f5c-dbd4c765542c'}>

as you see _signature and hmac_key have different values and i think this 
is the reason i get non authorized alert when i add 
@auth.requires_signature() to controller.

what is the correct way to do this?
  

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: postgres error

2013-03-21 Thread yashar
thank you, very helpful.

On Thursday, March 21, 2013 11:57:40 PM UTC+3:30, Niphlod wrote:
>
> just to clear out doubts.
> a field 'reference sometable' gets:
>  - a foreign key to the id of sometable
>  - a validator that by default builds up on the format argument of 
> sometable
>
> you CAN'T have a foreign key to a table and have the requires parameter 
> with is_in_db() building a string value.
> So, if you want the 'origin' field to store the integer that is a pointer 
> to the countries.id table, while retaining the country_name while 
> representing it in the dropdown, you should do
>
> db.define_table('countries', 
>Field('country_name'),
>format='%(country_name)s'
> )
> db.define_table('testing',
> Field('origin','reference countries')
>
> ) 
>
> or
>
> db.define_table('countries', 
>Field('country_name'),
> )
> db.define_table('testing',
> Field('origin','reference countries',requires=IS_IN_DB(
> db,'countries.id', '%(country_name)s',error_message='Choose origin 
> country'))
> )
>
> if you want testing.origin to be a string holding country names (so, not a 
> reference), with the dropdown showing  the countries you have in the 
> countries table
>
> db.define_table('countries', 
>Field('country_name'),
> )
> db.define_table('testing',
> Field('origin',requires=IS_IN_DB(
> db,'countries.country_name',error_message='Choose origin country'))
> )
>
>
>
> tl;dr your "mix and match" doesn't specify what you want. Field type 
> "trumps" the requires parameter on a database level. 
>
> On Thursday, March 21, 2013 9:02:20 PM UTC+1, Cliff Kachinske wrote:
>>
>> The syntax may be correct per the manual, but IS_IN_DB tells Postgres to 
>> create a foreign key constraint on the field.  If you look at the tables 
>> with psql or pgadmin you will see this is so.
>>
>> A foreign key constraint is always on the primary key of the foreign 
>> table.  It has to be this way to guarantee uniqueness.
>>
>> This will work:
>>
>> countries = [r.countryname for r in 
>> db(somequery).select(db.countries.countryname)]
>>
>> db.testing.origin.requires = IS_IN_SET(countries)
>>
>>
>>
>> On Thursday, March 21, 2013 3:36:51 PM UTC-4, Alan Etkin wrote:
>>>
>>> > there is no string validator, i just use IS_IN_DB to create drop down 
>>> widget
>>>
>>> Yes, sorry, I checked the api and it seems you are using the correct 
>>> syntax.
>>>
>>> Does it work using  IS_IN_DB (db, db.countries.country_name) instead? 
>>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: postgres error

2013-03-21 Thread yashar
there is no string validator, i just use IS_IN_DB to create drop down widget

On Thursday, March 21, 2013 10:26:38 PM UTC+3:30, Alan Etkin wrote:
>
> the form is created by the admin app, no validation error, just i get this 
>> error for any insert with relation.
>>
>
> Wait, your model has something odd (at least for me)
>
> Since countries is a reference value, AFAIK, it must be an integer. But 
> you are using a string validator. I don't think that's legal. If you remove 
> the validator, it should work fine. I think you need to set the constraint 
> in another way.
>  
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: postgres error

2013-03-21 Thread yashar
the form is created by the admin app, no validation error, just i get this 
error for any insert with relation.

i dont understand.

On Thursday, March 21, 2013 10:06:54 PM UTC+3:30, Alan Etkin wrote:
>
>  insert or update on table "testing" 
>> violates foreign key constraint "sea_inquery_origin_fkey" DETAIL: Key 
>> (origin)=(0) is not present in table "countries". 
>
>
> Are you setting 0 value for the foreign key?
>
> If you are in the admin app, the insert form should not pass validation 
> unless you specify an actual db record as reference.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] postgres error

2013-03-21 Thread yashar
db.define_table('countries',
Field('country_name')
)

db.define_table('testing',
Field('origin','reference 
countries',requires=IS_IN_DB(db,'countries.country_name',error_message='Choose 
origin country'))
)

when i try to input testing from database administration, i get this error:

 insert or update on table "testing" 
violates foreign key constraint "sea_inquery_origin_fkey" DETAIL: Key 
(origin)=(0) is not present in table "countries". 


any idea? i create different tables but get same result.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: login by ajax

2013-03-01 Thread yashar
sorry for delay:





×
Log in 


You could login by your yahoo or gmail account.


{{=form}}






function login_process(user_type){
$('#Modallogin').modal('show');
$('#auth_user_type').val(user_type);
}

function login(){
var data = $('form').serialize(); 
$('form input').each(function(){$(this).attr('disabled',true);});
$('#login_result').removeClass('alert alert-error').text('');
$('#login_result').addClass('alert alert-info').text('Connecting...');
$.ajax({  
  type: "POST",  
url: '{{=URL('default','index')}}',  
  data: data,
success : function(response){
$('form input').each(function(){$(this).attr('disabled',false);});
try{
response = jQuery.parseJSON(response);
}
catch(e){
var response = {'msg':'failed to proceed'};
} 
if (!response.logged){
$('#login_result').removeClass('alert alert-info').addClass('alert 
alert-error').text(response.msg);
}else{
window.location=response.redirect;
}
}
});  
return false;
}




On Thursday, February 28, 2013 4:15:50 AM UTC+3:30, Massimo Di Pierro wrote:
>
> I still do not understand. Why index() is under returning some times json 
> and some times dict with a form? Who makes the ajax callback? If this to be 
> embedded in a large page? What is the JS?
>
> On Wednesday, 27 February 2013 14:49:04 UTC-6, yashar wrote:
>>
>> def ajax_login_bare(self, username, password):
>> """
>> check user login and
>> return tuple of (boolean,msg) which first field is successfull login or 
>> not
>> and second is failure massage 
>> """
>>
>> request = current.request
>> session = current.session
>> table_user = self.settings.table_user
>> if self.settings.login_userfield:
>> userfield = self.settings.login_userfield
>> elif 'username' in table_user.fields:
>> userfield = 'username'
>> else:
>> userfield = 'email'
>> passfield = self.settings.password_field
>> key = {userfield:username,passfield:password}
>> user = self.db(table_user[userfield] == username).select().first()
>> if user:
>> # user in db, check if registration pending or disabled
>> temp_user = user
>> if temp_user.registration_key == 'pending':
>> return (False,self.messages.registration_pending)
>> elif temp_user.registration_key in ('disabled', 'blocked'):
>> return (False,self.messages.login_disabled)
>> elif not temp_user.registration_key is None and 
>> temp_user.registration_key.strip():
>> return (False,self.messages.registration_verifying)
>> # try alternate logins 1st as these have the
>> # current version of the password
>> user = None
>> for login_method in self.settings.login_methods:
>> if login_method != self and 
>> login_method(username,password):
>> if not self in self.settings.login_methods:
>> # do not store password in db
>> password = None
>> user = self.get_or_create_user(key)
>> break
>> if not user:
>> # alternates have failed, maybe because service inaccessible
>> if self.settings.login_methods[0] == self:
>> # try logging in locally using cached credentials
>> if password == temp_user[passfield]:
>> # success
>> user = temp_user
>> else:
>> # user not in db
>> if not self.settings.alternate_requires_registration:
>> # we're allowed to auto-register users from external systems
>> for login_method in self.settings.login_methods:
>> if login_method != self and 
>> login_method(username,password):
>> if not self in self.settings.login_methods:
>> # do not store password in db
>> key[passfield] = None
>> user = self.get_or_cr

[web2py] Re: login by ajax

2013-02-27 Thread yashar
def ajax_login_bare(self, username, password):
"""
check user login and
return tuple of (boolean,msg) which first field is successfull login or not
and second is failure massage 
"""

request = current.request
session = current.session
table_user = self.settings.table_user
if self.settings.login_userfield:
userfield = self.settings.login_userfield
elif 'username' in table_user.fields:
userfield = 'username'
else:
userfield = 'email'
passfield = self.settings.password_field
key = {userfield:username,passfield:password}
user = self.db(table_user[userfield] == username).select().first()
if user:
# user in db, check if registration pending or disabled
temp_user = user
if temp_user.registration_key == 'pending':
return (False,self.messages.registration_pending)
elif temp_user.registration_key in ('disabled', 'blocked'):
return (False,self.messages.login_disabled)
elif not temp_user.registration_key is None and 
temp_user.registration_key.strip():
return (False,self.messages.registration_verifying)
# try alternate logins 1st as these have the
# current version of the password
user = None
for login_method in self.settings.login_methods:
if login_method != self and login_method(username,password):
if not self in self.settings.login_methods:
# do not store password in db
password = None
user = self.get_or_create_user(key)
break
if not user:
# alternates have failed, maybe because service inaccessible
if self.settings.login_methods[0] == self:
# try logging in locally using cached credentials
if password == temp_user[passfield]:
# success
user = temp_user
else:
# user not in db
if not self.settings.alternate_requires_registration:
# we're allowed to auto-register users from external systems
for login_method in self.settings.login_methods:
if login_method != self and 
login_method(username,password):
if not self in self.settings.login_methods:
# do not store password in db
key[passfield] = None
user = self.get_or_create_user(key)
break
if not user:
self.log_event(self.messages.login_failed_log,request.post_vars)
return (False,self.messages.invalid_login)
else:
user = Row(table_user._filter_fields(user, id=True))
# process authenticated users
# user wants to be logged in for longer
self.login_user(user)
session.auth.expiration = \
request.vars.get('remember', False) and \
self.settings.long_expiration or \
self.settings.expiration
session.auth.remember = 'remember' in request.vars
self.log_event(self.messages.login_log, user)
return (True,self.messages.logged_in)



def index():
if request .post_vars:
from gluon.serializers import json
logged,msg =  auth.ajax_login_bare(request 
.vars.email,request 
.vars.password)
if logged:
return json(dict(redirect 
=get_user_info(),logged=logged,msg=msg))
else: 
return json(dict(logged=logged,msg=msg))

form = auth.login()

return dict(form=form) 

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: login by ajax

2013-02-20 Thread yashar

this is what i added in tools.py inside auth class, this is just 
modification of login() function and difference from main login_bare is 
this one also check, creates and logs in users which authenticated with 
other authentication methods.


def ajax_login_bare(self, username, password):
"""
check user login and
return tuple of (boolean,msg) which first field is successfull 
login or not
and second is failure massage 
"""

request = current.request
session = current.session
table_user = self.settings.table_user
if self.settings.login_userfield:
userfield = self.settings.login_userfield
elif 'username' in table_user.fields:
userfield = 'username'
else:
userfield = 'email'
passfield = self.settings.password_field
key = 
{userfield:request.vars[userfield],passfield:request.vars[passfield]}
user = self.db(table_user[userfield] == 
request.vars[userfield]).select().first()
if user:
# user in db, check if registration pending or disabled
temp_user = user
if temp_user.registration_key == 'pending':
return (False,self.messages.registration_pending)
elif temp_user.registration_key in ('disabled', 'blocked'):
return (False,self.messages.login_disabled)
elif not temp_user.registration_key is None and 
temp_user.registration_key.strip():
return (False,self.messages.registration_verifying)
# try alternate logins 1st as these have the
# current version of the password
user = None
for login_method in self.settings.login_methods:
if login_method != self and 
login_method(request.vars[userfield],request.vars[passfield]):
if not self in self.settings.login_methods:
# do not store password in db
request.vars[passfield] = None
user = self.get_or_create_user(key)
break
if not user:
# alternates have failed, maybe because service inaccessible
if self.settings.login_methods[0] == self:
# try logging in locally using cached credentials
if request.vars.get(passfield, '') == 
temp_user[passfield]:
# success
user = temp_user
else:
# user not in db
if not self.settings.alternate_requires_registration:
# we're allowed to auto-register users from external systems
for login_method in self.settings.login_methods:
if login_method != self and 
login_method(request.vars[userfield],request.vars[passfield]):
if not self in self.settings.login_methods:
# do not store password in db
key[passfield] = None
user = self.get_or_create_user(key)
break
if not user:
self.log_event(self.messages.login_failed_log,request.post_vars)
return (False,self.messages.invalid_login)
else:
user = Row(table_user._filter_fields(user, id=True))
# process authenticated users
# user wants to be logged in for longer
self.login_user(user)
session.auth.expiration = \
request.vars.get('remember', False) and \
self.settings.long_expiration or \
self.settings.expiration
session.auth.remember = 'remember' in request.vars
self.log_event(self.messages.login_log, user)
return (True,self.messages.logged_in)


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: login by ajax

2013-02-19 Thread yashar
i think login_bare needs to write again, in login() function, it first 
checks the login_methods and then local database and also 
create_or_get_user and update session.auth, but in login_bare it just check 
the database if user is there add it to session but not doing any of the 
login() steps which brings many problems like if user changed his gmail 
password.
i think login_bare should be just like login() with the difference of 
instead of returning form it should return messages in pliantext or json.

On Monday, February 18, 2013 9:04:48 PM UTC+3:30, Massimo Di Pierro wrote:
>
> self.login_bare() calls self.login_user(...) and it automatically logs 
> in the user and stores user in session.auth.user
>
>
>
>  

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: login by ajax

2013-02-17 Thread yashar
is there any way that i log in user by code?

for example after checking username and password with login_bare, i push 
the user into the session as logged in user? in this case there is no need 
to write ajax/login directly, and the programmer has a better control.

if i write :
def login():

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: login by ajax

2013-02-17 Thread yashar
thank you, i solve the problem like this:

def index():
form = auth.login()
form.elements('input',_type='submit')[0]['_Onclick']='login();return 
false;'
return dict(form=form)

def login():
if not auth.login_bare(request.vars.email,request.vars.password):
return 'login failed'
form=auth.login()
if auth.user : return 'logged'
return dict(form=form)

and in the index view:


{{=form}}


function login(){
alert('here');
$.ajax({  
  type: "POST",  
url: '{{=URL('default','login')}}',  
  data: $('form').serialize(),
success : function(data){
if (data != 'True'){
$('#login_result').addClass('alert 
alert-error').text('Email Or password were wrong! Please try again.');
} else {
   
   }
}
});  
return false;
}




-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] login by ajax

2013-02-17 Thread yashar
login form is modal form inside index, and send login form via ajax to 
login() function, but i can not login.

def login():
form=auth.login()
if form.accepts(request,session=None):
return 'logged'
else: return 'failed'

below section is in index page view: 
  


Email

Password

Submit




function login(){
$.ajax({  
  type: "POST",  
url: '{{=URL('default','login')}}',  
  data: 
'email='+$('#email').val()+'&password='+$('#password').val(),
success : function(data){
if (data != 'logged){
$('#login_result').addClass('alert 
alert-error').text('Email Or password were wrong! Please try again.');
} else {
   alert('logged');
   }
}
});  

}



i also tried auth.login_bare in login() function , but it doesnt update 
session. any idea to what should i do to correct this?

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: different form of registration based on

2013-01-03 Thread yashar
thanks, i think that i should use auth.register.on_success and 
auth.register.on_validation methods for your first advice.

-- 





[web2py] different form of registration based on

2013-01-03 Thread yashar

i have two different set of users to register, employees and employers. 
their common fields are , username, email, active, password but the rest of 
the fields are different, how should i create register form for each one? 

is this possible to do something like this somewhere in registration 
function:

registration_form.process(dbio=false).accept:
id=insert non-common fields into x-table
registration_form.insert(**fields,registration_form.vars.forign_id=id)

beside that what can i do? 

-- 





[web2py] Re: what is wrong with this function in view

2012-12-09 Thread yashar

it works, thank you.

-- 





[web2py] Re: Ref: custom form issue

2012-12-09 Thread yashar
insert like this:
{{form.insert(0,my_extra_element)}}

return like this:
{{=form[0]}}

if this solve your problem.

-- 





[web2py] what is wrong with this function in view

2012-12-09 Thread yashar
i get syntax error for the first 'elif', i tried if pass, if pass... but i 
wasnt able to escape error, what is wrong?

{{
def populate_row(value):
currency_map={'U':'USD','E':'Euro','P':'Pound'}
if value:
currency = value[-1:].upper()
value = int(value[:-1])
pass
if (value < 0 and currency == 'B') : return 
XML('%s'%value)
elif ( value > 0 and currency == 'B') : return 
XML('%s'%value)
elif (value < 0) : return XML('%s 
%s'%(value,currency_map[currency]) ) 
elif (value > 0) : return XML('%s 
%s'%(value,currency_map[currency]) )
pass
}}




-- 





[web2py] Re: sqlform hidden values

2012-10-10 Thread yashar
i read that many times and i thought thats under the hod! thanks

On Wednesday, October 10, 2012 4:51:55 PM UTC+3:30, Anthony wrote:
>
> It should be available in request.vars.DN (and request.post_vars.DN).
>
> From the book:
>
> There is a special hidden attribute. When a dictionary is passed as hidden, 
> its items are translated into "hidden" INPUT fields (see the example for 
> the FORM helper in Chapter 5).
>
> form = SQLFORM(,hidden=...)
>
> causes the hidden fields to be passed with the submission, no more, no 
> less. form.accepts(...) is not intended to read the received hidden 
> fields and move them into form.vars. The reason is security. hidden fields 
> can be tampered with. So you have to do explicitly move hidden fields from 
> the request to the form:
>
> form = SQLFORM(..., hidden=dict(a='b'))
> form.vars.a = request.vars.a
>
>
>
> Anthony
>
> On Wednesday, October 10, 2012 9:02:45 AM UTC-4, yashar wrote:
>>
>> this is my form:
>>
>> form = 
>> SQLFORM(db.records,record_id,showid=False,deletable=True,hidden=dict(DN=DN))
>>
>> but i cannot access form.vars.DN in controler nither in validator 
>> function, in controller in returns error ( DN is not in table ) and in 
>> validator it returns None.
>>
>

-- 





[web2py] Re: conditionally process form

2012-10-10 Thread yashar


On Tuesday, October 9, 2012 8:14:54 PM UTC+3:30, Annet wrote:
>
> In a function I have the following code:
>
>validate(form):
  organization=db((db.
>
> organization.cocNumber==form.vars.cocNumber)&\
> 
> (db.organization.subdossierNumber==form.vars.subdossierNumber)).select(db.organization.ALL)

  if organization:
   form.error.exist = 'Y'
 
 

> form=SQLFORM.factory(...)  
>
if form.process(keepvalues=True,onvalidation=validate).accepted:
>
   processForm(form)
else:
   form.process(keepvalues=True).accepted:
   processthisone(form)

return dict(form=form)
>
> The problem is that some organizations do have the same coc_number and 
> subdossier_number but differ in name and address, so after the warning 
> flash I'd like to be able to submit the form again and just call 
> processForm(form) so without checking whether the database contains the 
> organization or not.
>
> What is the best way to code this?
>
>
> Kind regards,
>
> Annet.
>
>

-- 





[web2py] sqlform hidden values

2012-10-10 Thread yashar
this is my form:

form = 
SQLFORM(db.records,record_id,showid=False,deletable=True,hidden=dict(DN=DN))

but i cannot access form.vars.DN in controler nither in validator function, 
in controller in returns error ( DN is not in table ) and in validator it 
returns None.

-- 





[web2py] Re: i get 'server error'

2012-10-06 Thread yashar
solved
redirect url is wrong

-- 





[web2py] i get 'server error'

2012-10-06 Thread yashar
this is in controller:

@auth.requires_login()
def check_DN_owning_email():
query = (db.DN_table.state == request.vars.link) & (db.DN_table.user_id 
== auth.user_id)
row = db(query).select().first()
if row :
row.update_record(state='Confirmed')
response.flash = T('Now you can renew your account')
else:
response.flash = T('Confirmation string mismatch')
redirect('default','my_panel')

there is no view

it updates the record, but return 'server error' and this is in shell after 
running:

ERROR:Rocket.Errors.Thread-8:Traceback (most recent call last):

  File "/home/yashar/Documents/web2py/gluon/rocket.py", line 1302, in run
self.run_app(conn)

  File "/home/yashar/Documents/web2py/gluon/rocket.py", line 2003, in 
run_app
output = self.app(environ, self.start_response)

  File "/home/yashar/Documents/web2py/gluon/main.py", line 693, in 
app_with_logging
ret[0] = wsgiapp(environ, responder2)

  File "/home/yashar/Documents/web2py/gluon/main.py", line 617, in wsgibase
http_response, request, environ, ticket)

  File "/home/yashar/Documents/web2py/gluon/rewrite.py", line 202, in 
try_rewrite_on_error
status = int(str(http_response.status).split()[0])

ValueError: invalid literal for int() with base 10: 'my_panel'


is this a bug? or i did something wrong?

-- 





Re: [web2py] varchar size in database

2012-09-25 Thread yashar
thanks

On Tuesday, September 25, 2012 3:22:54 PM UTC+3:30, Marin Pranjić wrote:
>
> Field(..., length=255, ...)
>
> Marin
>
> On Tue, Sep 25, 2012 at 1:28 PM, yashar >wrote:
>
>> my database is postgres and i'm using this:
>>
>> Field('name',required=IS_LENGTH(255));
>>
>> but it creates a varchar(512) in database,
>>
>> , how could i fix it?
>>
>> -- 
>>  
>>  
>>  
>>
>
>

-- 





[web2py] varchar size in database

2012-09-25 Thread yashar
my database is postgres and i'm using this:

Field('name',required=IS_LENGTH(255));

but it creates a varchar(512) in database,

, how could i fix it?

-- 





[web2py] Re: Read file attached from gmail

2012-09-18 Thread yashar
check this:

http://stackoverflow.com/questions/8307809/save-email-attachment-python3-pop3-ssl-gmail

On Tuesday, September 18, 2012 2:53:35 AM UTC+4:30, visuallinux wrote:
>
> Dear All. 
>
> Every day i did received a email (gmail) with a file attached (text) as 
> rar. 
>
> My question is how i can read this file attached from web2py? 
>
> Or how i can download this file to /tmp folder? 
>
> Any idea. 
>
> Regards 
>
>
>
>
>
>

-- 





[web2py] Re: manipulate db.field.attrib

2012-09-16 Thread yashar
thanks , it worked. i was thinking to use sqlform factory to create a form 
and push it into database.

On Sunday, September 16, 2012 7:45:39 PM UTC+4:30, Anthony wrote:
>
> The problem is not that you are changing the validator in each form 
> function -- the form always gets submitted back to its original function, 
> so the validator will always be set the same, both on form creation and 
> form submission/validation. The problem is that when you create the form, 
> it gets a default name and a hidden _formkey field associated with that 
> name. The _formkey is also stored in the session and used to prevent CSRF 
> attacks and double submission. When you create form2, it overwrites the 
> _formkey value of form1 in the session because both forms have the same 
> name. If you then try to submit form1, it won't validate. To solve the 
> problem, just give each form a unique name:
>
> form.process(..., formname='form1')
>
> Anthony
>
> On Sunday, September 16, 2012 7:12:52 AM UTC-4, yashar wrote:
>>
>> below solution not working, because when you open form1 then form2, 
>> web2py will look for joe for field, and not saving form1, so how could i 
>> solve it?
>>
>> db.define_table('test',
>> Field('name'))
>>
>> def form1():
>> db.test.name.requires=IS_IN_SET(['yashar'])
>> form = SQLFORM(db.test)
>> if form.process().accepted:
>> pass
>> return dict(form=form)
>> 
>> def form2():
>> db.test.name.requires=IS_IN_SET(['Joe'])
>> form = SQLFORM(db.test)
>> if form.process().accepted:
>> pass
>> return dict(form=form)
>>
>>
>>
>>

-- 





[web2py] manipulating dal.field.attrib

2012-09-16 Thread yashar
i used this:

db.define_table('test',
Field('service_type'))

def form1():
db.test.service_type.requires=IS_IN_SET(['Trial'])
form = SQLFORM(db.test)
if form.process().accepted:
pass
return dict(form=form)

def form2():
db.test.service_type.requires=IS_IN_SET(['one month','one year'])
form = SQLFORM(db.test)
if form.process().accepted:
pass
return dict(form=form)

but this is not working, when you open form1 and then form2 and then submit 
form1 it is not saving any data.

so db.test.service_type.requires=IS_IN_SET(['one month','one year']) is not 
creating an instance for this form but setting that requires for all forms, 
how to solve it?

-- 





[web2py] manipulate db.field.attrib

2012-09-16 Thread yashar
below solution not working, because when you open form1 then form2, web2py 
will look for joe for field, and not saving form1, so how could i solve it?

db.define_table('test',
Field('name'))

def form1():
db.test.name.requires=IS_IN_SET(['yashar'])
form = SQLFORM(db.test)
if form.process().accepted:
pass
return dict(form=form)

def form2():
db.test.name.requires=IS_IN_SET(['Joe'])
form = SQLFORM(db.test)
if form.process().accepted:
pass
return dict(form=form)



--