Exemplo n.º 1
0
        public static void Create(AppDb context, DbUsers nu)
        {
            DbUsers u = context.Users.FirstOrDefault(m => m.Login == nu.Login);

            if (u == null)
            {
                nu.DateCreate        = DateTime.Now;
                nu.LastAuthorization = DateTime.Now;
                nu.IsActive          = true;
                nu.IsDelete          = false;

                context.Users.Add(nu);
            }
            else
            {
                throw new Exception("Login busy");
            }
        }
Exemplo n.º 2
0
        public static string Authorization(AppDb context, string Login, string Password)
        {
            DbUsers u = context.Users.FirstOrDefault(m => m.Login == Login && m.Password == Password);

            if (u == null)
            {
                throw new Exception("Wrong login or password");
            }
            else
            {
                u.LastAuthorization = DateTime.Now;
                do
                {
                    u.AuthorizationKey = Utility.Rand(32);
                    DbUsers _u = context.Users.FirstOrDefault(m => m.AuthorizationKey == u.AuthorizationKey);
                    if (_u == null)
                    {
                        break;
                    }
                }while (true);
                return(u.AuthorizationKey);
            }
        }