public async Task <ActionResult> Post([FromBody] TSUser tsUser)
        {
            string UserID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "UserID", 10);

            await TS.AddActivityLog(UserID, "post user", MethodBase.GetCurrentMethod());


            GlobalFunctions.CmdDecryptEntityAsymm(tsUser);


            bool b = TS.DeleteExpiredEmaiedCodes().Result;


            string MachineID = GlobalFunctions.CmdGetValueFromClaim(User.Claims, "MachineID", 10);

            string IPAddress = HttpContext.Connection.RemoteIpAddress.ToString();



            TSEmailedCodeEntity emailedCode = TS.FindEmaiedCode(tsUser.Email, IPAddress, MachineID).Result;

            if (emailedCode != null)
            {
                if (emailedCode.Code.ToLower().Equals(tsUser.EmailedCode))
                {
                    await TS.DeleteEmaiedCodes(tsUser.Email);

                    tsUser.UserID = await TS.GetNewID("AllUsers", "LastUserID", true);

                    tsUser.CreateDate = DateTime.Now;


                    b = await TS.AddUser(tsUser);

                    if (b)
                    {
                        await TS.UpdateSettingCounter("AllUsers", "UsersCount", true);


                        await GlobalFunctions.NotifyAdmin("New user");

                        return(Ok("OK"));
                    }
                    else
                    {
                        return(Ok("Error:Can't add new user!"));
                    }
                }
                else
                {
                    return(Ok("Error:Emailed code is not correct!"));
                }
            }
            else
            {
                await TS.AddErrorLog("AllUsers", "EmaiedCode expected but not found", MethodBase.GetCurrentMethod());

                return(Ok("Error:Server can't find emailed code to compare!"));
            }
        }
Ejemplo n.º 2
0
        private static async Task <bool> CmdSaveEmailedCode(TSEmailedCode ParEmailedCode)
        {
            bool result = true;

            try
            {
                bool b = await TS.DeleteExpiredEmaiedCodes();

                b = await TS.DeleteEmaiedCodes(ParEmailedCode.Email);

                result = await TS.AddEmailedCode(ParEmailedCode);
            }
            catch (Exception ex)
            {
                await TS.AddErrorLog("AllUsers", ex.Message, MethodBase.GetCurrentMethod());

                result = false;
            }
            return(result);
        }