コード例 #1
0
ファイル: UserController.cs プロジェクト: murukeshs/Golf
        public IActionResult generateOTP([FromBody] GenOTP otp)
        {
            try
            {
                string res = "";
                //Random generator = new Random();
                //int OTPValue = generator.Next(0, 999999);

                int OTPValue = Common.GenerateOTP();

                Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
                Match match = regex.Match(otp.email);
                if (otp.type == "" || otp.type == "string")
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest, new { error = new { message = "Please enter a type" } }));
                }
                else if (match.Success)
                {
                    string row = Data.User.generateOTP(OTPValue, otp);

                    if (row == "Success")
                    {
                        res = Common.SendOTP(otp.email, otp.type, OTPValue);
                        if (res == "Mail sent successfully.")
                        {
                            return(StatusCode((int)HttpStatusCode.OK, "OTP Generated and sent Successfully")); //result = "Mail sent successfully.";
                        }
                        else
                        {
                            return(StatusCode((int)HttpStatusCode.OK, "OTP Generated, mail not sent Successfully"));
                        }
                    }
                    else
                    {
                        //return "Invalid user";
                        return(StatusCode((int)HttpStatusCode.Forbidden, new { error = new { message = row } }));
                    }
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.BadRequest, new { error = new { message = "Please enter a valid Email" } }));
                }
            }
            catch (Exception e)
            {
                string SaveErrorLog = Data.Common.SaveErrorLog("generateOTP", e.Message);

                return(StatusCode((int)HttpStatusCode.InternalServerError, new { error = new { message = e.Message } }));
            }
        }
コード例 #2
0
ファイル: User.cs プロジェクト: murukeshs/Golf
        public static string generateOTP(int OTPValue, [FromBody] GenOTP otp)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@OTPValue", OTPValue));
            parameters.Add(new SqlParameter("@email", otp.email));
            parameters.Add(new SqlParameter("@type", otp.type));

            try
            {
                string ConnectionString = Common.GetConnectionString();

                string rowsAffected = SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, "spGenerateOTP", parameters.ToArray()).ToString();
                return(rowsAffected);
            }
            catch (Exception e)
            {
                //loggerErr.Error(e.Message + " - " + e.StackTrace);
                throw e;
            }
        }