Ejemplo n.º 1
0
        public async Task <IActionResult> Login([FromBody] UsernamePasswordResource credentials)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new { message = "Username and password have to be supplied" }));
            }

            if (string.IsNullOrWhiteSpace(credentials.Username))
            {
                return(BadRequest(new { message = "Username not supplied" }));
            }
            if (string.IsNullOrWhiteSpace(credentials.Password))
            {
                return(BadRequest(new { message = "Password not supplied" }));
            }

            var token = await service.Login(credentials.Username, credentials.Password);

            if (token != "")
            {
                if (token == "PasswordChangeRequired")
                {
                    return(BadRequest(new { Message = token }));
                }
                else
                {
                    return(Ok(new { token }));
                }
            }
            else
            {
                return(BadRequest(new { message = "Invalid username/password supplied" }));
            }
        }
Ejemplo n.º 2
0
        public async Task <int> UpdateUser(UsernamePasswordResource newUser)
        {
            var user = await ILogin.GetLoginInfos(newUser.username);

            mapper.Map <UsernamePasswordResource, LoginInfo>(newUser, user);
            return(ILogin.Saver());
        }
Ejemplo n.º 3
0
        public async Task <int> email(UsernamePasswordResource username)
        {
            string toEmail = null;
            string name    = null;
            var    s       = new Students();
            var    t       = new Teachers();
            //var user = con.LoginInfo.Where(li => li.UserName == u.username).FirstOrDefault();
            var user = await ILogin.GetLoginInfos(username.username);

            if (user != null)
            {
                if (user.UserType == "S")
                {
                    s = await ILogin.getStudent(user.Id);

                    name    = s.FirstName + " " + s.LastName;
                    toEmail = ILogin.getEmail(user.Id, true);
                }
                else
                {
                    t = await ILogin.getTeacher(user.Id);

                    name    = t.FirstName + " " + t.LastName;
                    toEmail = ILogin.getEmail(user.Id, false);
                    //toEmail = con.Teachers.Where(s => s.TeacherId == user.Id).FirstOrDefault().EmailId;
                }
            }

            if (toEmail == null)
            {
                return(0);
            }

            string sendermail = "*****@*****.**";
            string senderpswd = "sfsdf";

            SmtpClient cli = new SmtpClient("smtp.gmail.com", 587);

            cli.EnableSsl             = true;
            cli.Timeout               = 10000;
            cli.DeliveryMethod        = SmtpDeliveryMethod.Network;
            cli.UseDefaultCredentials = false;
            cli.Credentials           = new NetworkCredential(sendermail, senderpswd);

            Random r   = new Random();
            int    otp = r.Next(000111, 999999);

            string body = "<h2>Dear " + name + ",</h2><br><p>2Your OTP generated at " +
                          DateTime.Now.ToString() + " for Password change is: " + otp + "</p><br><h5>Thank You for using " +
                          "<strong>Student Management System</strong> By Huzefa Galiakotwala<br>Regards<br>Huzefa Galiakotwala</h5>";

            MailMessage mail = new MailMessage(sendermail, toEmail, "OTP for Password Change", body);

            mail.IsBodyHtml   = true;
            mail.BodyEncoding = UTF8Encoding.UTF8;
            cli.Send(mail);

            return(otp);
        }
Ejemplo n.º 4
0
        public async Task <LoginInfo> GetLoginInfos(UsernamePasswordResource ob)
        {
            return(await db.LoginInfo.Where(log => log.UserName == ob.username &&
                                            log.UserPassword == ob.password)
                   .FirstOrDefaultAsync());


            //return await db.LoginInfo.Where(log => log.UserName == ob.username
            //                                        && log.UserPassword == ob.password)
            //                                            .ToListAsync();
        }
Ejemplo n.º 5
0
        public async Task <LoginIdTypeResource> CheckUser(UsernamePasswordResource ob)
        {
            //var db = new StudentContext();
            //var user = await db.LoginInfo.Where(log =>log.UserName == ob.username
            //                                        && log.UserPassword == ob.password)
            //                                            .ToListAsync();

            var user = await ILogin.GetLoginInfos(ob);

            if (user != null)
            {
                return(mapper.Map <LoginInfo, LoginIdTypeResource>(user));
            }
            else
            {
                return(null);
            }
        }