<commit_before>﻿using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Neo4j.AspNet.Identity;
using Neo4jClient;
using Dal;

namespace Solitude.Server
{
    [RoutePrefix("api/user")]
    public class UserController : ApiController
	{
        private SolitudeUserManager manager;

        public UserController() {}
        public UserController(SolitudeUserManager manager)
		{
            this.Manager = manager;
		}

        public SolitudeUserManager Manager
        {
            get
            {
                return manager ?? Request.GetOwinContext().GetUserManager<SolitudeUserManager>();
            }
            private set
            {
                manager = value;
            }
        }

        public IGraphClient DB
        {
            get
            {
                return Request.GetOwinContext().Get<GraphClientWrapper>().GraphClient;
            }
        }

		[AllowAnonymous]
		[Route("register")]
		public async Task<IHttpActionResult> Register(User user)
		{
            var appUser = new ApplicationUser() { UserName = user.UserName };

            var result = await Manager.CreateAsync(appUser, user.Password);

            IHttpActionResult errorResult = GetErrorResult(result);

            if (errorResult != null)
            {
                return errorResult;
            }
                
            return Ok();
		}

        [Authorize]
        [Route("delete")]
        public async Task<IHttpActionResult> Delete()
        {
            var user = await Manager.FindByIdAsync(User.Identity.GetUserId());

            var result = await Manager.DeleteAsync(user);

            IHttpActionResult errorResult = GetErrorResult(result);<commit_msg>server: validate user model<commit_after>﻿using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using Neo4j.AspNet.Identity;
using Neo4jClient;
using Dal;

namespace Solitude.Server
{
    [RoutePrefix("api/user")]
    public class UserController : ApiController
	{
        private SolitudeUserManager manager;

        public UserController() {}
        public UserController(SolitudeUserManager manager)
		{
            this.Manager = manager;
		}

        public SolitudeUserManager Manager
        {
            get
            {
                return manager ?? Request.GetOwinContext().GetUserManager<SolitudeUserManager>();
            }
            private set
            {
                manager = value;
            }
        }

        public IGraphClient DB
        {
            get
            {
                return Request.GetOwinContext().Get<GraphClientWrapper>().GraphClient;
            }
        }

		[AllowAnonymous]
		[Route("register")]
		public async Task<IHttpActionResult> Register(User user)
		{
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var appUser = new ApplicationUser() { UserName = user.UserName };

            var result = await Manager.CreateAsync(appUser, user.Password);

            IHttpActionResult errorResult = GetErrorResult(result);

            if (errorResult != null)
            {
                return errorResult;
            }
                
            return Ok();
		}

        [Authorize]
        [Route("delete")]
        public async Task<IHttpActionResult> Delete()
        {
            var user = await Manager.FindByIdAsync(User.Identity.GetUserId());

            var result = await Manager.DeleteAsync(user);

            IHttpActionResult errorResult = GetErrorResult(result);
{'fraction_non_alphanumeric': 0.0860446356547459, 'fraction_numerical': 0.0010755579456843238, 'mean_word_length': 1.8748068006182381, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '665363', 'n_tokens_mistral': 960, 'n_tokens_neox': 917, 'n_words': 196}