<commit_before>/**
 * Copyright 2015 LinkedIn Corp. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */
package controllers.api.v1;

import com.fasterxml.jackson.databind.node.ObjectNode;
import dao.UserDAO;
import java.util.List;
import models.CompanyUser;
import models.Group;
import models.UserEntity;
import org.apache.commons.lang3.StringUtils;
import play.cache.Cache;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
import java.util.Map;


public class User extends Controller
{
    private static final String CACHE_INTERNAL_USERS = "internal.users.cache";
    private static final String CACHE_INTERNAL_GROUPS = "internal.groups.cache";
    private static final String CACHE_INTERNAL_ENTITIES = "internal.entities.cache";

    public static Result getLoggedInUser()
    {
        ObjectNode result = Json.newObject();

        result.put("status", "ok");
        String username = session("user");
        result.set("user", Json.toJson(UserDAO.getCurrentUser(username)));
        return ok(result);
    }


    public static Result updateSettings()
    {
        Map<String, String[]> params = request().body().asFormUrlEncoded();
        ObjectNode result = Json.newObject();

        String username = session("user");
        if (StringUtils.isNotBlank(username))
        {
            String message = UserDAO.updateUserSettings(params, username);
            if (StringUtils.isBlank(message))
            {
                result.put("status", "success");
            }
            else
            {
                result.put("status", "failed");
                result.put("message", message);
            }
        }
        else
        {
            result.put("status", "failed");
            result.put("message", "User is not authenticated");
        }
        return ok(result);<commit_msg>Add check for user not in session, at get current user API<commit_after>/**
 * Copyright 2015 LinkedIn Corp. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */
package controllers.api.v1;

import com.fasterxml.jackson.databind.node.ObjectNode;
import dao.UserDAO;
import java.util.List;
import models.CompanyUser;
import models.Group;
import models.UserEntity;
import org.apache.commons.lang3.StringUtils;
import play.cache.Cache;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
import java.util.Map;


public class User extends Controller
{
    private static final String CACHE_INTERNAL_USERS = "internal.users.cache";
    private static final String CACHE_INTERNAL_GROUPS = "internal.groups.cache";
    private static final String CACHE_INTERNAL_ENTITIES = "internal.entities.cache";

    public static Result getLoggedInUser()
    {
        ObjectNode result = Json.newObject();

        String username = session("user");
        if (StringUtils.isBlank(username))
        {
            result.put("status", "failed");
            result.put("message", "no user in session");
            return ok(result);
        }

        models.User user = UserDAO.getCurrentUser(username);
        if (StringUtils.isBlank(user.userName))
        {
            result.put("status", "failed");
            result.put("message", "can't find user info");
            return ok(result);
        }

        result.set("user", Json.toJson(user));
        result.put("status", "ok");
        return ok(result);
    }

    public static Result updateSettings()
    {
        Map<String, String[]> params = request().body().asFormUrlEncoded();
        ObjectNode result = Json.newObject();

        String username = session("user");
        if (StringUtils.isNotBlank(username))
        {
            String message = UserDAO.updateUserSettings(params, username);
            if (StringUtils.isBlank(message))
            {
                result.put("status", "success");
            }
            else
            {
                result.put("status", "failed");
                result.put("message", message);
            }
        }
        else
        {
            result.put("status", "failed");
            result.put("message", "User is not authenticated");
        }
        return ok(result);
{'fraction_non_alphanumeric': 0.1091127098321343, 'fraction_numerical': 0.003996802557953637, 'mean_word_length': 2.6294416243654823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '112981', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1323, 'n_words': 387}