Ejemplo n.º 1
0
        public async Task <int> EmailTimeSave(EmailTimeSaveModel objreq)
        {
            int result = await Task <int> .Run(() =>
            {
                return(_objFriendFitDBEntity.Database.ExecuteSqlCommandAsync("AddMailSentTime @UserId=@UserId,@ResetMail=@ResetMail,@VerifyMail=@VerifyMail,@MailSentTime=@MailSentTime",
                                                                             new SqlParameter("UserId", objreq.UserId),
                                                                             new SqlParameter("ResetMail", objreq.@ResetMail),
                                                                             new SqlParameter("VerifyMail", objreq.VerifyMail),
                                                                             new SqlParameter("MailSentTime", objreq.MailSentTime)));
            });

            return(result);
        }
        public async Task <HttpResponseMessage> ResendMailForForget(string Email)
        {
            FResponse result = new FResponse();

            try
            {
                Int64  UserId    = _objFriendFitDBEntity.Database.SqlQuery <Int64>("select Id from UserProfile where Email={0}", Email).FirstOrDefault();
                string UserToken = _objFriendFitDBEntity.Database.SqlQuery <string>("select TokenCode from UserToken where UserId={0}", UserId).FirstOrDefault();
                if (Email != null)
                {
                    var SendingMessage = new MailMessage();
                    SendingMessage.To.Add(new MailAddress(Email));                   // replace with valid value
                    SendingMessage.From       = new MailAddress("*****@*****.**"); // replace with valid value
                    SendingMessage.Subject    = "Verify your email (noti.fit)";
                    SendingMessage.Body       = "Hi,<br/>You've requested a reset of your noti.fit password. If you didn't make the request, please ignore this email and your password won't be reset.<br/><br/> You can reset your password by visiting <br/> <br/><a href='" + ChangePasswordUrl + UserToken + "'>" + ChangePasswordUrl + UserToken + "</a> <br/><br/>This email will be valid for the next 12 hours.,<br/><br/><br/><br/>Kind regards<br/>The noti.fit team";
                    SendingMessage.IsBodyHtml = true;

                    using (var smtp = new SmtpClient())
                    {
                        var credential = new NetworkCredential
                        {
                            UserName = "******",  // replace with valid value
                            Password = "******" // replace with valid value
                        };
                        smtp.Credentials = credential;
                        smtp.Host        = "smtp.gmail.com";
                        smtp.Port        = 587;
                        smtp.EnableSsl   = true;
                        await smtp.SendMailAsync(SendingMessage);
                    }
                    //track sent Email time for expiry time :

                    EmailTimeSaveModel objreq = new EmailTimeSaveModel();
                    objreq.UserId       = UserId;
                    objreq.ResetMail    = true;
                    objreq.VerifyMail   = false;
                    objreq.MailSentTime = DateTime.Now.TimeOfDay;
                    EmailTrackerWrapper wrapper = new EmailTrackerWrapper();
                    wrapper.EmailTimeSave(objreq);
                    result.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
                    result.Message    = "Please check your Email for further instructions";
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }

            _response = Request.CreateResponse(HttpStatusCode.OK, result);
            return(_response);
        }
        public async Task <HttpResponseMessage> ResendRegistrationMaiil(string Email)
        {
            FResponse result = new FResponse();

            try
            {
                Int64  UserId    = _objFriendFitDBEntity.Database.SqlQuery <Int64>("Select Id from UserProfile where Email={0}", Email).FirstOrDefault();
                string UserToken = _objFriendFitDBEntity.Database.SqlQuery <string>("select TokenCode from UserToken where UserId={0}", UserId).FirstOrDefault();
                if (Email != null)
                {
                    var SendingMessage = new MailMessage();
                    SendingMessage.To.Add(new MailAddress(Email));                   // replace with valid value
                    SendingMessage.From       = new MailAddress("*****@*****.**"); // replace with valid value
                    SendingMessage.Subject    = "Verify your email (noti.fit)";
                    SendingMessage.Body       = "Hi,<br/>Congratulations on signing up to noti.fit, the fitness tracker that keeps you honest!<br/><br/>Please visit <a href='" + RegistrationUrl + UserToken + "'>" + RegistrationUrl + UserToken + "</a> <br/>  to verify your email address and activate your account, or copy the link into a browser if you can't open it from your email address.<br/><br/>Kind regards,<br/>The noti.fit team";
                    SendingMessage.IsBodyHtml = true;

                    using (var smtp = new SmtpClient())
                    {
                        var credential = new NetworkCredential
                        {
                            UserName = "******",  // replace with valid value
                            Password = "******" // replace with valid value
                        };
                        smtp.Credentials = credential;
                        smtp.Host        = "smtp.gmail.com";
                        smtp.Port        = 587;
                        smtp.EnableSsl   = true;
                        await smtp.SendMailAsync(SendingMessage);
                    }
                    //track sent Email time for expiry time :

                    EmailTimeSaveModel objreq = new EmailTimeSaveModel();
                    objreq.UserId       = UserId;
                    objreq.ResetMail    = false;
                    objreq.VerifyMail   = true;
                    objreq.MailSentTime = DateTime.Now.TimeOfDay;
                    EmailTrackerWrapper wrapper = new EmailTrackerWrapper();
                    wrapper.EmailTimeSave(objreq);

                    result.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
                    result.Message    = "Please check your Email for further instructions";
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
            _response = Request.CreateResponse(HttpStatusCode.OK, result);
            return(_response);
        }
        public async Task <HttpResponseMessage> UserSignUp(SignUpModelRequset objSignUpModelRequset)
        {
            SignUpResponseModelResponse result = new SignUpResponseModelResponse();

            if (ModelState.IsValid)
            {
                try
                {
                    IsPasswordValid = (Regex.IsMatch(objSignUpModelRequset.Password, passwordRegex));
                    //if (IsPasswordValid == true)
                    //{
                    string IsMailIdExist = _objFriendFitDBEntity.Database.SqlQuery <string>("Select Email from UserProfile where Email={0}", objSignUpModelRequset.Email).FirstOrDefault();

                    if (IsMailIdExist == null)
                    {
                        var    model       = _objIUserSettings.AddUser(objSignUpModelRequset);
                        Random random      = new Random();
                        Int64  otp         = Convert.ToInt64(random.Next(1000, 9999)); /// to specify range for random number
                        Int64  UserId      = _objFriendFitDBEntity.Database.SqlQuery <Int64>("Select Id from UserProfile where Email={0}", objSignUpModelRequset.Email).FirstOrDefault();
                        int    rowEffected = _objFriendFitDBEntity.Database.ExecuteSqlCommand("CreateNewToken @UserId=@UserId,@TokenCode=@TokenCode,@ExpiryDate=@ExpiryDate",
                                                                                              new SqlParameter("UserId", UserId),
                                                                                              new SqlParameter("TokenCode", Guid.NewGuid().ToString() + UserId.ToString() + Guid.NewGuid().ToString()),
                                                                                              new SqlParameter("ExpiryDate", DateTime.Now.AddDays(7)));

                        string Token = _objFriendFitDBEntity.Database.SqlQuery <string>("Select TokenCode from UserToken where UserId={0}", UserId).FirstOrDefault();
                        //mail sending after registration
                        if (objSignUpModelRequset.Email != null)
                        {
                            var SendingMessage = new MailMessage();
                            SendingMessage.To.Add(new MailAddress(objSignUpModelRequset.Email)); // replace with valid value
                            SendingMessage.From       = new MailAddress("*****@*****.**");     // replace with valid value
                            SendingMessage.Subject    = "Verify your email (noti.fit)";
                            SendingMessage.Body       = "Hi,<br/>Congratulations on signing up to noti.fit, the fitness tracker that keeps you honest!<br/><br/>Please visit <a href='" + RegistrationUrl + Token + "'>" + RegistrationUrl + Token + "</a> <br/>  to verify your email address and activate your account, or copy the link into a browser if you can't open it from your email address.<br/><br/>Kind regards,<br/>The noti.fit team";
                            SendingMessage.IsBodyHtml = true;

                            using (var smtp = new SmtpClient())
                            {
                                var credential = new NetworkCredential
                                {
                                    UserName = "******",      // replace with valid value
                                    Password = "******"     // replace with valid value
                                };
                                smtp.Credentials = credential;
                                smtp.Host        = "smtp.gmail.com";
                                smtp.Port        = 587;
                                smtp.EnableSsl   = true;
                                await smtp.SendMailAsync(SendingMessage);
                            }


                            //track sent Email time for expiry time :

                            EmailTimeSaveModel objreq = new EmailTimeSaveModel();
                            objreq.UserId       = UserId;
                            objreq.ResetMail    = false;
                            objreq.VerifyMail   = true;
                            objreq.MailSentTime = DateTime.Now.TimeOfDay;
                            EmailTrackerWrapper wrapper = new EmailTrackerWrapper();
                            wrapper.EmailTimeSave(objreq);

                            result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
                            result.Response.Message    = "Please check your Email for further instructions";
                        }
                        else
                        {
                            FileStream   fs  = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Content/ErrorLog.txt"), FileMode.Append, FileAccess.Write);
                            StreamWriter swr = new StreamWriter(fs);
                            swr.Write("Enter ur Exception Here");
                            swr.Close();
                            result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.Unauthorized);
                            result.Response.Message    = "This Mail Id is not registered";
                        }


                        //mail SMS after registration
                        if (objSignUpModelRequset.MobileNumber != null)
                        {
                            twilioModel tm = new twilioModel();
                            tm.countryCode = objSignUpModelRequset.CountryId;
                            tm.mobileNo    = objSignUpModelRequset.MobileNumber;
                            tm.messagebody = "Hi " + objSignUpModelRequset.FirstName + ", Welcome to noti.fit. Please confirm your mobile at <a href='" + RegistrationUrl + Token + "'>" + RegistrationUrl + Token + "</a> - If this wasn't you, ignore this SMS or decline at the link";
                            var SMSStatus = SMSCont.SendSMS(tm);

                            //track sent Email time for expiry time :
                            EmailTimeSaveModel objreq = new EmailTimeSaveModel();
                            objreq.UserId       = UserId;
                            objreq.ResetMail    = false;
                            objreq.VerifyMail   = true;
                            objreq.MailSentTime = DateTime.Now.TimeOfDay;
                            EmailTrackerWrapper wrapper = new EmailTrackerWrapper();
                            wrapper.EmailTimeSave(objreq);

                            result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
                            result.Response.Message    = "Please check your Mobile for further instructions";
                        }
                        else
                        {
                            FileStream   fs  = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Content/ErrorLog.txt"), FileMode.Append, FileAccess.Write);
                            StreamWriter swr = new StreamWriter(fs);
                            swr.Write("Enter ur Exception Here");
                            swr.Close();
                            result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.Unauthorized);
                            result.Response.Message    = "This Mobile No. is not registered";
                        }
                        //
                        if (model > 0)
                        {
                            result.Response.Token      = Token;
                            result.Response.UserId     = UserId;
                            result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
                            result.Response.Message    = "Check your email and confirm your account, you must be confirmed " + " " + "before you can log in.";
                        }
                        else
                        {
                            result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.NotAcceptable);
                            result.Response.Message    = "The Data which you are providing it is in the wrong format";
                        }
                    }
                    else
                    {
                        result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.Ambiguous);
                        result.Response.Message    = "MailID elready Exist";
                    }
                    //}
                    //else
                    //{

                    //    result.StatusCode = Convert.ToInt32(HttpStatusCode.NotAcceptable);
                    //    result.Message = "Password Must contain at least one number and one uppercase and lowercase letter,  and atleast one special character and  must be in between 6 to 20 characters";

                    //}
                }
                catch (Exception ex)
                {
                    result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.BadRequest);
                    _response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Some error occurred");
                }
                _response = Request.CreateResponse(HttpStatusCode.OK, result);
            }
            else
            {
                ModelState.AddModelError("", "One or more errors occurred.");
            }
            return(_response);
        }
        public async Task <HttpResponseMessage> UserForgetPassword(ForgetPasswordRequest reqForgetPasswordRequest)
        {
            FResponse result = new FResponse();

            try
            {
                Int64 UserId = _objFriendFitDBEntity.Database.SqlQuery <Int64>("select Id from UserProfile where Email={0}", reqForgetPasswordRequest.Email).FirstOrDefault();

                if (UserId != 0)
                {
                    _objIUserSettings.UpdateToken(UserId);
                    string token = _objFriendFitDBEntity.Database.SqlQuery <string>("select TokenCode from UserToken where UserId={0}", UserId).FirstOrDefault();

                    string Email = _objFriendFitDBEntity.Database.SqlQuery <string>("Select Email from UserProfile Where Id=" + UserId).FirstOrDefault();


                    var SendingMessage = new MailMessage();
                    SendingMessage.To.Add(new MailAddress(Email));                   // replace with valid value
                    SendingMessage.From       = new MailAddress("*****@*****.**"); // replace with valid value
                    SendingMessage.Subject    = "Password Reset (noti.fit)";
                    SendingMessage.Body       = "Hi,<br/>You've requested a reset of your noti.fit password. If you didn't make the request, please ignore this email and your password won't be reset.<br/><br/> You can reset your password by visiting <br/> <br/><a href='" + ChangePasswordUrl + token + "'>" + ChangePasswordUrl + token + "</a> <br/><br/>This email will be valid for the next 12 hours.,<br/><br/><br/><br/>Kind regards<br/>The noti.fit team";
                    SendingMessage.IsBodyHtml = true;

                    using (var smtp = new SmtpClient())
                    {
                        var credential = new NetworkCredential
                        {
                            UserName = "******",  // replace with valid value
                            Password = "******" // replace with valid value
                        };
                        smtp.Credentials = credential;
                        smtp.Host        = "smtp.gmail.com";
                        smtp.Port        = 587;
                        smtp.EnableSsl   = true;
                        await smtp.SendMailAsync(SendingMessage);
                    }
                    //track sent Email time for expiry time :

                    EmailTimeSaveModel objreq = new EmailTimeSaveModel();
                    objreq.UserId       = UserId;
                    objreq.ResetMail    = true;
                    objreq.VerifyMail   = false;
                    objreq.MailSentTime = DateTime.Now.TimeOfDay;
                    EmailTrackerWrapper wrapper = new EmailTrackerWrapper();
                    wrapper.EmailTimeSave(objreq);

                    result.StatusCode = Convert.ToInt32(HttpStatusCode.OK);
                    result.Message    = "Please check your Email for further instructions";
                }
                else
                {
                    FileStream   fs  = new FileStream(System.Web.HttpContext.Current.Server.MapPath("~/Content/ErrorLog.txt"), FileMode.Append, FileAccess.Write);
                    StreamWriter swr = new StreamWriter(fs);
                    swr.Write("Enter ur Exception Here");
                    swr.Close();
                    result.StatusCode = Convert.ToInt32(HttpStatusCode.Unauthorized);
                    result.Message    = "This Mail Id is not registered";
                }
                var message = Request.CreateResponse(HttpStatusCode.Created, result);
                return(message);
            }
            catch (Exception ex)
            {
                result.StatusCode = Convert.ToInt32(HttpStatusCode.BadRequest);
                _response         = Request.CreateResponse(HttpStatusCode.InternalServerError, "Some error occurred");
            }
            return(_response);
        }