A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: User permission levels

  1. #1
    Senior Member
    Join Date
    Feb 2003
    Posts
    129

    User permission levels

    Hello,

    I've managed to get a User Login working for my website. The users details are kept on a separate .txt file in the same directory, called members.txt.
    Here's how the text file looks:

    Code:
    memberData=User1,password1,[email protected],6
    User2,password2,[email protected],4&
    &eof=yes&
    The login button is coded as follows:

    Code:
    on (release, keyPress "<Enter>") {
    	user=user;
    	for (var ndx = 0; ndx<totalMembers; ++ndx) {
    		if (user == memberArray[ndx][0]) {
    			if (pass == memberArray[ndx][1]) {
    				gotoAndStop("Website", 1);
    				success = true;
    				userlevel = memberArray[ndx][3];
    				youremail=memberArray[ndx][2];
    				password=memberArray[ndx][1];
    				Submit = "Yes";
    			}
    		}
    		if (false == success) {
    			gotoAndStop(4);
    			error = "Login details incorrect. Please try again.";
    		}
    	}
    }
    The login works fine. See the numbers at the end of each line in the members.txt file? That's the user permission level. I've got a button (only accessed once logged in) that requires the user's level to be at least 5. As you can see, I've got two users so far, one is level 4, one is level 6. I've done this so I can test this section out.

    My problem is that both users can still access the level 5 section. Here's the code on the button:

    Code:
    on (release) {
    	_root.userlevel = memberArray[ndx][3];
    	trace(_root.userlevel);
    	// what is the result ?
    	trace(typeof _root.userlevel);
    	// what is the result ?
    	trace(ndx);
    	// is this index number viable ?
    	trace(memberArray[ndx][3]);
    	// undefined ??
    	trace(_root.memberArray[ndx][3]);
    	// what result here with _root.prefix ??
    	if (_root.userlevel>="5") {
    		pages.gotoAndStop("special");
    	}
    	// end if
    }
    Also, from the traces in that code, I get the following results:

    Code:
    undefined
    undefined
    2
    undefined
    undefined
    Can anyone see what I've done wrong here? Any help is greatly appreciated.

    Thanks.

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You are dealing with Strings not numbers. You need to convert the String first:

    _root.userlevel = Number(memberArray[ndx][3]);
    ..........
    if (_root.userlevel>=5) {
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Alright, so now I'm using this code for the button:

    Code:
    on (release) {
    	_root.userlevel = Number(memberArray[ndx][3]);
    	if (_root.userlevel>=5) {
    		pages.gotoAndStop("special");
    	}
    }
    And still get the same result. Is this incorrect, or is part of the other coding incorrect?

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You have other problems there as well. I don't see where you load the textfield data to the movie. Then don't use scripts associated with buttons. Place all scripts on the main timeline.

    myBut.onPress = function()
    {
    //function here
    }

    The reason why you get undefined is, because the data are not at _root.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Quote Originally Posted by cancerinform
    You have other problems there as well. I don't see where you load the textfield data to the movie.
    I've got this code on the first frame of the movie:
    Code:
    var memberData = this.loadVariables("members.txt", 0);
    So that's alright, isn't it?

    Then don't use scripts associated with buttons. Place all scripts on the main timeline.

    myBut.onPress = function()
    {
    //function here
    }
    And now I've removed the code from the button and given the button the instance name "specialbutton" and given the timeline this code:

    Code:
    specialbutton.onPress = function()
    {
    _root.userlevel = Number(memberArray[ndx][3]);
    	if (_root.userlevel>=5) {
    		pages.gotoAndStop("special");
    	}
    }
    
    stop();
    It still gives the same outcome. I think it's because of...

    The reason why you get undefined is, because the data are not at _root.
    Where do I change this?

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    If you use the loadVariables function you need to wait until the loading is completed. You can go to the next frame or you can use event Dispatcher method or ASBroadcaster.

    However, loadVariables is Flash 5 syntax. You should use LoadVars. i have attached some files.
    Attached Files Attached Files
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    That works well but it's not quite what I'm after.

    Once the user has logged in, they will see the same main screen as every other user. There's then a "Special" button that only certain levels of users can access. So the access level needs to be determined at that point, not at the login.

    Any clues?

  8. #8
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    This is seriously urgent now. Is anyone able to help me? A small reward will be given.

  9. #9
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    this might help
    Code:
    user = SharedObject.getLocal("user_profile");
    
    if (user.data.name == undefined){
             //Not Logged In
    	_root.gotoAndStop("form");
    } else {
    	firstname = user.data.firstname;
    	name = user.data.name;
    	computer = user.data.computer;
    	_root.gotoAndStop("done");
    }
    http://www.kirupa.com/developer/mx/sharedobjects.htm :for a more complete tutorial

    http://www.adobe.com/support/flash/a...shared_object/ : more info...

    by the way thats not a very secure login form at all
    you should really login with php using sessions and store info in a mysql DB....

  10. #10
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Thanks for the help, but also not quite what I'm after.

    Good news though, I've done it.

    I changed the permission level on the login button code to this:



    Code:
    _root.userlevel=Number(memberArray[ndx][3]);


    And changed the Special area's button to this:



    Code:
    specialbutton.onPress = function()
    {
     if (_root.userlevel>=5) {
      pages.gotoAndStop("special");
     }
    }
    
    stop();

  11. #11
    Senior Member
    Join Date
    Feb 2003
    Posts
    129
    Ok, seems I haven't done it. I've noticed the "if" condition on the Special button doesn't seem to recognise the userlevel as either text OR numbers.

    I'm at my wits end now, I need this done ASAP and I'm willing to pay anyone who can sort out this whole mess.

    My MSN is [email protected].

    Add me and I can send you the files required for altering.

  12. #12
    Senior Member Genesis F5's Avatar
    Join Date
    Jan 2002
    Location
    Unallocated memory
    Posts
    1,845
    What are you using this for? Anything with private user information should never be handled with an external txt file.

    The biggest problem you're having is by trying to store an array in the text file. Variables need to be URL-encoded in a url query fashion (example: myvar1=1&myvar2=2). You can't store arrays within the external file. Try to read variable "memberData." You'll notice that it's a string and not an array. That's why you're receiving undefined variables.

    This should be handled (like Cancerinform said) with LoadVars, but instead of an external file, through a serverside (PHP, Perl, ect) request.

    One note: For readability, say "if(something == false)", or the more efficient "if(!something)."

    If you insist on using an external file, it will have to be XML.You can do it with an external text file, but you'll have to implement some special form of parsing to extract the data from the string.

    Remember, though, XML and text files are cached, so anyone can go to their temporary files folder and have access to your whole database.
    Last edited by Genesis F5; 05-16-2007 at 10:38 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center