+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Logging in through a web api issues recording user details

Logging in through a web api issues recording user details

2 posts, 0 answered
  1. bryan
    bryan avatar
    10 posts
    Registered:
    11 Apr 2016
    16 Sep
    Link to this post

    howdy, i am trying to block access to my site's api unless they're authenticated. i have a POST function that contains the following:

     if (manager.ValidateUser(username, password))
                    {
                        DateTime now = DateTime.UtcNow;
                        var user = manager.GetUser(username);

                        user.IsLoggedIn = true;
                        user.LastLoginIp = HttpContext.Request.UserHostAddress;
                        user.LastLoginDate = now;
                        user.LastActivityDate = now;

                        UserLoggingReason validate = SecurityManager.AuthenticateUser(UserManager.GetDefaultProviderName(), username, password, true, out user);

                        if (validate.Equals(UserLoggingReason.UserAlreadyLoggedIn))
                        {
                            SecurityManager.Logout(UserManager.GetDefaultProviderName(), user.Id);
                            validate = SecurityManager.AuthenticateUser(UserManager.GetDefaultProviderName(), username, password, true, out user);
                        }

                        if (validate.Equals(UserLoggingReason.Success))
                        {
                            manager.Provider.SuppressSecurityChecks = true;
                            manager.SaveChanges();
                        }

    The issue seems to lie in the manager.SaveChanges() spot as it attempts to save the minor changes to the user. The following error gets generated:

     

    Telerik.OpenAccess.Exceptions.OptimisticVerificationException: Row not found: GenericOID@e62cbf64 User id=977bacc3-79d6-6539-9d49-ff0000f4184f
            UPDATE [sf_users] SET [fld_psswrd_ttempt_window_start]=?, [is_logged_in]=?, [last_login_date]=?, [last_modified]=? WHERE [id] = ? AND [fld_psswrd_ttempt_window_start]=? AND [is_logged_in]=? AND [last_login_date]=? AND [last_modified]=?
                (set event logging to all to see parameter values)

     

    I have seen across multiple threads that i am not the only one with this issue but from what i've seen its a concurrency issue...but in my case i hit this error every time, and i'm the only one testing the function. So i've no idea how to get around this. Am i even using the correct sitefinity way to allow a script to login and access my api? Thank you

  2. bryan
    bryan avatar
    10 posts
    Registered:
    11 Apr 2016
    3 days and 5 hours ago
    Link to this post
    bump. i'd appreciate help with this as soon as is possible. thank you
2 posts, 0 answered