Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.

Announcement

If you wish to join the Developer Exchange, please contact your account manager - this is to avoid unnecessary spam in the forums. Many thanks for your understanding.

#1 2013-12-13 15:45:38

FarhanaJabbar
Member
Registered: 2013-10-03
Posts: 9

how to Auto login, after user account creation from API

Hi,

I am creating user account if not already created using json api CreateUser. Currently user is receiving email to reset password and it also activate user.
Is there any way that i can activate user by API and auto login him from my application using impersonate.

Regards

Farhana

Offline

#2 2013-12-13 15:58:05

dominic
Third Light Staff
Registered: 2013-06-06
Posts: 96

Re: how to Auto login, after user account creation from API

Hi Farhana,

Via the API there is no need for a separate activation step: that is only required for the user to choose a password.

Using the API method Users.SetAuthMode you can change the authentication mechanism to "no_password" - in this state, they will not be able to log in directly or set a password.

You can log them in from your application by calling Core.GetAuthorisedURL and directing the user to the returned URL.

Dominic

Offline

#3 2013-12-13 17:10:44

FarhanaJabbar
Member
Registered: 2013-10-03
Posts: 9

Re: how to Auto login, after user account creation from API

Thank you very much. it worked for me.

Offline

#4 2014-02-03 11:56:42

FarhanaJabbar
Member
Registered: 2013-10-03
Posts: 9

Re: how to Auto login, after user account creation from API

hi there,

I am having a problem with user creation using API with no-password option. Users are still getting emails with change password link and when they click the link, it does not work for them.
and then they are unable to access the system at all. always get redirect to changepassword page.

is there any solution for this. it is urgent please.

this is the code for user creation

var createUser = new
                    {
                        action = "Users.CreateUser",
                        apiVersion = "1.0",
                        inParams =
                            new
                            {
                                username = userName,
                                description = string.Format("{0} {1}", employee.Firstname, employee.Surname),
                                email = employee.EmailAddress,
                                preset = "g:" + _userGroupId
                            },
                        sessionId = _sessionId
                    };

                    response = client.PostAsJsonAsync("/api.json.tlx", createUser).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        result = response.Content.ReadAsStringAsync().Result;
                        var newUserId = JsonConvert.DeserializeObject<JsonResponse<NewUserIdOutParams>>(result).outParams.id;

                        var setAuthMode = new
                        {
                            action = "Users.SetAuthMode",
                            apiVersion = "1.0",
                            inParams =
                                new
                                {
                                    userId = newUserId,
                                    authMode = "no_password"
                                },
                            sessionId = _sessionId
                        };

                        client.PostAsJsonAsync("/api.json.tlx", setAuthMode);

Regards,

Farhana

Last edited by FarhanaJabbar (2014-02-03 12:01:44)

Offline

#5 2014-02-03 12:19:57

steve
Third Light Staff
Registered: 2013-06-06
Posts: 92

Re: how to Auto login, after user account creation from API

Hi Farhana,

Thanks for the details. Unfortunately there isn't currently a way to use the CreateUser() call without it sending an email. We would need to change it so that it can accept another argument that allows you to specify whether an email should be sent or not. I shall write this up as a feature request.

I'm sorry that we didn't know about this earlier as we might have been able to add something before you launched but I shall separately write back to David and yourself on the support ticket.

Best Regards,
Steve

Offline

#6 2014-02-06 18:08:11

steve
Third Light Staff
Registered: 2013-06-06
Posts: 92

Re: how to Auto login, after user account creation from API

IMS 6.0.18-3 versions and above will feature an extra argument to control whether the welcome email is sent:

Users.CreateUser(string username, string description, string email[, string preset = "normal"][, bool welcomeEmail = true]) → hash

Offline

Board footer