Forum for discussing general topics related to Couch.
7 posts Page 1 of 1
Hi, KK. I am just wonder is that any particular reason that member login by using email address not username?

Can I make user login by using username not email address? As this will be more consistent with the admin login. And can I make the system detect the username has registered just like system detect the email address?

Once again, It's requested from my client. I have no choice but solve it. Thanks.
Hi,

Both members module as well as the extended-users module are perfectly happy accepting usernames instead of emails (the '@' in the supplied value suffices to differentiate between the two).

If you choose to allow your members to login using their names, you are free to do so.
But remember that now at the time of creating the accounts, the members will have to input *two unique values* - the username and the email.

This was the practical reason why the sample code auto-generates a random name as user-name and asks only for the email.
What code should I added to make the username must be filled in while user register? And what code should I added to make the system detect that the username is existed?
Simply add a field named 'member_name' to the registration form and the member module will automatically map it to the k_page_name system field of the cloned-page that'll be created for the account -
Code: Select all
<cms:input name='member_name' type='text' />

You don't have to check if the name already exists as that would be done in any case (pages cannot have the same name).
Forgot to mention that you'd also want to make the field a required one (else the auto generated name would get used if the field is left empty) -
Code: Select all
<cms:input name='member_name' type='text' required='1' />
Hello KK,
I followed the above in order for users to login with a username instead: On form success at registration:
Code: Select all
<cms:form 
                masterpage=k_user_template
                mode='create'
                enctype='multipart/form-data'
                method='post'
                anchor='0'>
<cms:if k_success >
<cms:db_persist_form
                        _invalidate_cache='0'
                        k_page_name = "<cms:random_name />"
                    />
</cms:if>
<div class="form-field" data-field="Username">
                        <label for="username" class="feather icon-user"></label>
                        <cms:input name='member_name' type='text' required='1' id="username" placeholder="" />
                    </div>
</cms:form>


When I submit the form I get this error:
Title: Required field cannot be left empty
UPDATE: I did this and got the form to accept the username(member_name) as the page title
Code: Select all
<cms:form 
                masterpage=k_user_template
                mode='create'
                enctype='multipart/form-data'
                method='post'
                anchor='0'>

                <cms:if k_success >       

                    <cms:check_spam email=frm_extended_user_email />           

                    <cms:db_persist_form
                        _invalidate_cache='0'
                        k_page_title =frm_member_name
                    />                   

                    <cms:if k_success >       
                        <cms:set_flash name='success_msg' value='1' />
                        <cms:redirect k_page_link />
                    </cms:if>
                </cms:if>

                <cms:if k_error >
                    <font color='red'><cms:each k_error ><cms:show item /><cms:dump /><br /></cms:each></font>
                </cms:if>
                    <div class="form-field" data-field="First name">
                        <label for="firstname" class="feather icon-user"></label>
                        <cms:input type="bound" name="firstname" id="username" />
                    </div>

                    <div class="form-field" data-field="Last name">
                        <label for="last name" class="feather icon-user"></label>
                        <cms:input type="bound" name="lastname" id="username" required="required" />
                    </div>
                    <style type="text/css">
                   
                    </style>

                    <div class="form-field gender" data-field="Gender">
                <cms:input type="bound" name="gender"
                opt_values="Male | Female" />
                    </div>

                    <div class="form-field" data-field="Date of Birth(in dd-mm-yyyy format)">
                        <label for="dob" class="feather icon-calendar"></label>
                        <cms:input type="bound" name="dob" id="dob" required="required" placeholder='DD-MM-YYYY' />
                    </div>

                    <div class="form-field select-field grade" data-field="Grade/Class">
                        <cms:input name='grade' type='bound' id="grade" />
                        <i class="feather icon-chevron-down"></i>
                    </div>

                    <div class="form-field" data-field="Town/City">
                        <label for="town/city" class="feather icon-globe"></label>
                        <cms:input type="bound" name="town_city" id="town-city" required='1' />
                    </div>

                    <div class="form-field select-field" data-field="Region">
                        <label for="region" class="feather icon-globe"></label>
                        <cms:input name='region' type='bound' id="region" />
                        <i class="feather icon-chevron-down"></i>
                    </div>

                    <div class="form-field" data-field="Username">
                        <label for="username" class="feather icon-user"></label>
                        <cms:input name='member_name' type='text' required='1' id="username" placeholder="" />
                    </div>

                    <div class="form-field" data-field="Password">
                        <label for="password" class="feather icon-lock"></label>
                        <cms:input name='extended_user_password' type='bound' id="password" />
                    </div>

                    <div class="form-field" data-field="Confirm Password">
                        <label for="Confirm password" class="feather icon-lock"></label>
                        <cms:input name='extended_user_password_repeat' type='bound' id="confirm-password" />
                    </div>

                    <div class="form-field" data-field="Email">
                        <label for="Email" class="feather icon-mail"></label>
                        <cms:input name='extended_user_email' type='bound' id="email" />
                    </div>

                    <div class="form-extra-feature" style="margin-top: 25px;">
                        <span data-info="Already registered?"><a href="<cms:login_link k_login_template />" class="reg-login-button">Login</a></span>
                        <button type="submit">Register</button>
                    </div>
                </cms:form>


However when I tried registering with the same username, the form was submitted and the user created with a number appended to the page_name. I was expecting an error that says username exists. Can you please help me out?
7 posts Page 1 of 1

Who is online

In total there are 6 users online :: 0 registered, 0 hidden and 6 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 6 guests