示例#1
0
        public IActionResult GenrateOtp(string Email, int RoleId, string Name)
        {
            bool   isOtp = false;
            int    _min  = 1000;
            int    _max  = 9999;
            Random _rdm  = new Random();
            string Gotp  = _rdm.Next(_min, _max).ToString();

            string errMsg = string.Empty;

            try
            {
                var user = authHandler.GenerateOtp(Gotp, Email);
                if (!user)
                {
                    return(Json(new { isOtp = false, msg = "Email already exist" }));
                }
                if (RoleId == 3 || RoleId == 4)
                {
                    if (RoleId == 3 && Name == null)
                    {
                        Name = "Employer";
                    }
                    else if (RoleId == 4 && Name == null)
                    {
                        Name = "Stuffing Partner";
                    }
                    var eModel = new EmailViewModel
                    {
                        Subject = "Login OTP",
                        Body    = "Dear " + Name + "," + "<br/>" + Gotp + " is OTP to complete the registration."
                                  + "<br/>Do not disclose the OTP to anyone.<br/>Happy job post and search candidate with IT-ITeS Sector Skills Council NASSCOM." + "<br><br> Thank You" + "<br>Placement Portal Team",
                        To       = new string[] { Email },
                        From     = config["EmailCredential:Fromemail"],
                        IsHtml   = true,
                        MailType = (int)MailType.OTP
                    };
                    emailHandler.SendMail(eModel, -1);
                }

                else
                {
                    if (RoleId == 2 && Name == null)
                    {
                        Name = "Candidate";
                    }
                    else if (RoleId == 5 && Name == null)
                    {
                        Name = "Praining Partner";
                    }

                    var eModel = new EmailViewModel
                    {
                        Subject = "Login OTP",
                        Body    = "Dear " + Name + "," + "<br/>" + Gotp + " is OTP to complete the registration."
                                  + "<br/>Do not disclose the OTP to anyone.<br/>Happy job post and search candidate with IT-ITeS Sector Skills Council NASSCOM." + "<br><br> Thank You" + "<br>Placement Portal Team",
                        To       = new string[] { Email },
                        From     = config["EmailCredential:Fromemail"],
                        IsHtml   = true,
                        MailType = (int)MailType.OTP
                    };
                    emailHandler.SendMail(eModel, -1);
                }

                return(Json(new { isOtp = true }));
            }
            catch (UserNotCreatedException ex)
            {
                Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, 0, typeof(AuthController), ex);
                isOtp  = false;
                errMsg = ex.Message;
            }
            catch (Exception ex)
            {
                Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, 0, typeof(AuthController), ex);
                isOtp  = false;
                errMsg = ex.Message;
            }
            return(Json(new { isOtp, errMsg }));
        }