How to set allow modules to a user by server side script giving error "allow must be set first"

i am creating a user in user doctype using a web form i am trying to give permissions for a module to the user but it is giving the error “allow must be set first”