<commit_before>﻿using System.Collections.Generic;
using HRI.Models;
using System;
using System.Web.Mvc;
using System.Web.Security;
using Umbraco.Web.Models;

namespace HRI.Controllers
{
    public class RegisterSurfaceController : HriSufraceController
    {
        public const string PasswordNotStrongEnough = "The password is not strong enough";

        [HttpPost]
        [AllowAnonymous]
        public ActionResult HandleRegisterMember([Bind(Prefix = "registerModel")] RegisterFormViewModel model)
        {
            // Save Plan Id for the view
            ViewData["PlanId"] = model.PlanId;
            var error = false;

            // Check the Member Id (Y number)
            if (model.PlanId == null) // Enrolled user
            {
                var errorMessage = ValidateMemberIdCore(model.MemberId);

                if (errorMessage != null)
                {
                    ModelState.AddModelError("registerModel.MemberId", errorMessage);
                    error = true;
                }

                // if there's no error, try to get plan ID from api
                var planId = MakeInternalApiCall<string>("GetHealthPlanIdByMemberId",
                    new Dictionary<string, string> { { "memberId", model.MemberId } });
                if (planId != null)
                {
                    ViewData["PlanId"] = model.PlanId;
                    model.PlanId = planId;
                }
            }

            if (ModelState.IsValid == false || error)
                return CurrentUmbracoPage();

            // Create registration model and bind it with view model
            var registerModel = RegisterModel.CreateModel();
            registerModel.Name = model.Username;
            registerModel.UsernameIsEmail = false;
            registerModel.Email = model.Email;
            registerModel.Username = model.Username;
            registerModel.Password = <PASSWORD>;
            registerModel.RedirectUrl = "for-members/verify-account/";
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "firstName", Value = model.FirstName });
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "lastName", Value = model.LastName});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "ssn", Value = model.Ssn});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "zipCode", Value = model.Zipcode});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "phoneNumber", Value = model.Phone});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "yNumber", Value = model.MemberId});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "healthplanid", Value = model.PlanId});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "enrollmentpageafterlogin", Value = Convert.ToInt32(model.PlanId != null).ToString() });
<commit_msg>fix enroll after login so if you're already enrolled when signing up, you don't get that flag set<commit_after>﻿using System.Collections.Generic;
using HRI.Models;
using System;
using System.Web.Mvc;
using System.Web.Security;
using Umbraco.Web.Models;

namespace HRI.Controllers
{
    public class RegisterSurfaceController : HriSufraceController
    {
        public const string PasswordNotStrongEnough = "The password is not strong enough";

        [HttpPost]
        [AllowAnonymous]
        public ActionResult HandleRegisterMember([Bind(Prefix = "registerModel")] RegisterFormViewModel model)
        {
            // Save Plan Id for the view
            ViewData["PlanId"] = model.PlanId;
            var error = false;

            var enrollAfterLogin = Convert.ToInt32(model.PlanId != null).ToString();

            // Check the Member Id (Y number)
            if (model.PlanId == null) // Enrolled user
            {
                var errorMessage = ValidateMemberIdCore(model.MemberId);

                if (errorMessage != null)
                {
                    ModelState.AddModelError("registerModel.MemberId", errorMessage);
                    error = true;
                }

                // if there's no error, try to get plan ID from api
                var planId = MakeInternalApiCall<string>("GetHealthPlanIdByMemberId",
                    new Dictionary<string, string> { { "memberId", model.MemberId } });
                if (planId != null)
                {
                    ViewData["PlanId"] = model.PlanId;
                    model.PlanId = planId;
                }
            }

            if (ModelState.IsValid == false || error)
                return CurrentUmbracoPage();

            // Create registration model and bind it with view model
            var registerModel = RegisterModel.CreateModel();
            registerModel.Name = model.Username;
            registerModel.UsernameIsEmail = false;
            registerModel.Email = model.Email;
            registerModel.Username = model.Username;
            registerModel.Password = <PASSWORD>;
            registerModel.RedirectUrl = "for-members/verify-account/";
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "firstName", Value = model.FirstName });
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "lastName", Value = model.LastName});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "ssn", Value = model.Ssn});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "zipCode", Value = model.Zipcode});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "phoneNumber", Value = model.Phone});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "yNumber", Value = model.MemberId});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "healthplanid", Value = model.PlanId});
            registerModel.MemberProperties.Add(new UmbracoProperty { Alias = "enrollmentpageafterlogin", Value = enrollAfterLogin });

{'fraction_non_alphanumeric': 0.09411957950065702, 'fraction_numerical': 0.000657030223390276, 'mean_word_length': 2.275416890801506, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3738242', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1490, 'n_words': 366}